无法访问JSON的Childen

时间:2017-04-15 03:10:55

标签: json json.net jsonserializer

我需要能够遍历每个"项目"来自我的JSON结果。 JSON响应看起来像这样。我希望能够访问每个特定的ID。

{
"prop1": {
"date": "2017-03-04 3:57:38 PM",
"item": [
  {
    "id": "37705",
    "date": "2016-04-03",
    "time": "1:30PM"
    },
    "location": "Location 1"
  },
{
    "id": "2000",
    "date": "2016-05-03",
    "time": "2:30PM"
    },
    "location": "Location 2"
  },
  ] 
 }
}

这就是我所拥有的,但我得到了"无法访问儿童"

using (WebResponse response = await request.GetResponseAsync())
            {
                using (StreamReader stream = new StreamReader(response.GetResponseStream()))
                {
                    var serializer = new JsonSerializer();
                    using (var jsonTextReader = new JsonTextReader(stream))
                    {
                        dynamic obj = serializer.Deserialize(jsonTextReader);

                        foreach (var item in obj)
                        {
                            foreach (var item2 in item["item"].Children())
                            {
                                Console.WriteLine(item2.id);
                            }

                        }
                    }
                }
            }

0 个答案:

没有答案