C# Dictionary 字典嵌套 循環遍歷




調用接口,獲取到JSon數據后轉Dictinoary,結果是字典嵌套字典,內層字典是object類型,根本沒法foreach,最后在監視里面我發現內層的數據類型是這樣的,所以我就想着把object強制轉化成Dictionary 然后再進行遍歷得到我想要的數據
以下是我的全部遍歷Demo




 

 1  Dictionary<String, object> dt_acount = subaccount.JsonToDic();
 2                                     foreach (string key in dt_acount.Keys)
 3                                     {
 4                                         //object s = dt_acount["key"];
 5                                         if (key.Contains("SubAccount"))
 6                                         {
 7                                             Dictionary<String, object> acount = (Dictionary<String, object>)dt_acount["SubAccount"];
 8                                             foreach (string item in acount.Keys)
 9                                             {
10                                                 if (item.Contains("subAccountSid"))
11                                                 {
12                                                     model.ytx_subaccount = acount["subAccountSid"].ToString();
13                                                 }
14                                                 else if (item.Contains("subToken"))
15                                                 {
16                                                     model.ytx_subpass = acount["subToken"].ToString();
17                                                 }
18                                                 else if (item.Contains("voipAccount"))
19                                                 {
20                                                     model.ytx_subvoipaccount = acount["voipAccount"].ToString();
21                                                 }
22                                                 else if (item.Contains("voipPwd"))
23                                                 {
24                                                     model.ytx_subvoippass = acount["voipPwd"].ToString();
25                                                 }
26                                             }
27                                         }
28                                     }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM