0

再会,

我正在解析 JSON 响应。假设我有这个 JSON:

{
   "data": {
       "count" : 3,
       "innerData" : [
       {
           "dataInfo" : "heheh",
           "dataInfo2" : "hahah",
           "dataInfo3" : "huhuh"
       },
               {
           "dataInfo" : "jejej",
           "dataInfo2" : "jajaj",
           "dataInfo3" : "jujuj"
       },
               {
           "dataInfo" : "fefef",
           "dataInfo2" : "fafaf",
           "dataInfo3" : "fufuf"
       }
       ]
   }
}

好的。那么,如果我只想显示像“ dataInfo ”这样的数据怎么办......在Python中,我可以通过这样做轻松地做到这一点:

for x in response.json()['data']['innerData']
    print(x['dataInfo'])

这将显示:

>>> heheh
>>> jejej
>>> fefef

我怎样才能在 C# 中做到这一点?我试过这个: http: //procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net

但这仅适用于非数组 JSON ..

希望有人可以指导我,

4

1 回答 1

0

如果你使用 Json.NET

JObject obj = JObject.Parse(File.ReadAllText("1.json"));
foreach (JToken o in obj["data"]["innerData"] as JArray)
    Console.WriteLine(o["dataInfo"]);
于 2013-07-11T13:32:38.647 回答