2013-07-11 3 views
0

Bonjour,C# Parsing JSON Array (HTTPrequest Response) pour afficher

Je suis en train d'analyser la réponse JSON. Disons que j'ai ce JSON:

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

OK. Alors, que si je veux afficher uniquement les données comme « Datainfo » only..in Python, je peux facilement le faire en faisant ceci:

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

qui afficherait ceci:

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

Comment puis-je le faire en C#? J'ai essayé ceci: http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net

Mais cela ne fonctionnait pour les non-tableau JSON ..

quelqu'un L'espoir peut me guider,

Répondre

0

Si vous utilisez Json.NET

JObject obj = JObject.Parse(File.ReadAllText("1.json")); 
foreach (JToken o in obj["data"]["innerData"] as JArray) 
    Console.WriteLine(o["dataInfo"]); 
+0

Merci, cela ne le travail pour moi! –