Json错误 - 无法访问newtonsoft.json.linq.jproperty上的子值。

时间:2015-03-03 20:58:49

标签: json parsing

我有以下Json -

 Property {   
id: 122334,   
 source: 
 [ id : 123,     
    address:   
   {
  city: "little rock",   
  state: "Arkansas",   
   country: "USA"   
   },  
 unit:  
 {  
 id: 222,   
 name: "The wall",   
 count: 2   
  },  ]
 [ {id: 8889,   
   address:   
    {   
     city: "milka",   
      state: "Arkansas",  
         country: "USA"  
        },  
    unit:  
         {   
             id: 555,   
             name: "The watt",   
           count: 3   
            },   
        },   
       ]   
      }    

我按以下方式解析它 -

   string data = client.DownloadString(URL);     
                JToken token = JObject.Parse(data);      


    if (!string.IsNullOrEmpty(Convert.ToString(token["property"].Children())))
                {

                    token["property"].Children().ToList().ForEach(child =>
                        {

                            string GetID = Convert.ToString(child["source"]["unit"]["id"]); 

                            if (GetID == id)
                            {
                                //move rest of the code here
                            }
                            else
                            {

                            }

                        });      
                }    

但是我得到了execption - 无法访问newtonsoft.json.linq.jproperty上的子值。

在线 - string GetID = Convert.ToString(child [" source"] [" unit"] [" id"]);

我做错了什么?

enter code here

0 个答案:

没有答案