开发者

JSON nested array

Lets say i have the following JSON

{
   "data": [
      {
         "from": {
            "name": "aaa bbb",
         },
         "actions": [
            {
               "name": "Comment",
               "link": "http://...
            },
            {
               "name": "Like",
               "link": "http://.."
            }
         ],
      },

And i have

JSONObject wallData = helper.Get("/me/feed");
if (wallData != null)
{
    var data = wallData.Dictionary["data"];
    List<JSONObject> wallPosts = data.Array.ToList<JSONObject>();
}
foreach (Facebook.JSONObject wallItem in wallPosts)
{  ... }

Which stores me whole feed into wallData and 'data' object into wallPosts. So then i can access the wallItem.Dictionary["from"].Dictionary["name"], and i get "aaa bbb". But i can't get inside the actions array The w开发者_如何学GoallItem.Dictionary["actions"].Dictionary["name"] doesn't work.

Any idea


You need to do something like wallItem.Dictionary["actions"][0].Dictionary["name"] because "actions" is an array.


On a different note...its neater if u directly into a class...like this

var jSerializer = new JavaScriptSerializer();
var jsonObject = jSerializer.Deserialize<DataObject>(json);

The DataObject will be a class which emulates ur JSON data in a strongly typed class. Depending on the size of ur Json you will not have to use a lot of strings in your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜