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