2011-12-21 4 views
0

iDictionaryから友人リスト(以下)を取得する方法は?IDictionaryをJsonで使用しますか?

{ 
  "data": [ 
    { 
      "name": "John Smith", 
      "id": "111" 
    }, 
    { 
      "name": "Alice Smith", 
      "id": "222" 
    }, 
    { 
      "name": "Mary Smith", 
      "id": "333" 
    } 
  ], 
  "paging": { 
    "next": "https://graph.facebook.com/me/friends?format=json&limit=5000&offset=5000&__after_id=100003243976011" 
  } 
} 
あなたは、アプリケーション内でのSystem.WebとSystem.Web.Extensionsアセンブリ参照を追加する必要が

答えて

1
  1. その後
  2. コード

文字列以下使用するようにしてくださいjsonData = @ "{" "data" ":[{" "name" ":" John Smith ""、 "" id "": "111" "}、
""名前 "": ""メアリースミス ""、 "" ID: "": ""名前 "": ""アリススミス " "" "}]、
" "ページング" ":" ""次へ ":" "https://graph.facebook.com/me/friends?format=json &制限= 5000 &オフセット= 5000 & __after_id = 100003243976011 ""}} ";

  JavaScriptSerializer seri = new JavaScriptSerializer(); 
      var items = seri.Deserialize<Dictionary<string, object>>(jsonData); 
     // As data in JSON is array get it deserialize as ArrayList of Dictionary<string,object> 
      var dataArray = items["data"] as ArrayList;  
     // Each item in array list contain key value pair of name and id 
      foreach (Dictionary<string,object> item in dataArray) 
       { 
     //Read Item 
       foreach (KeyValuePair<string, object> detailItem in item) 
        { 
        Console.WriteLine(detailItem.Key + " - " + detailItem.Value); 
        } 
       Console.WriteLine("-------------------------------------------"); 
     // Read Item 
       } 
関連する問題