2

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 wallItem.Dictionary["actions"].Dictionary["name"] doesn't work.

Any idea

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Ok... so i put this into a Foreach ViewData["hm"] = wallItem.Dictionary["actions"][0].Dictionary["name"].String; It underlines me wallItem.Dictionary["actions"][0], error saying "Cannot apply indexing with [] to an expression of type Facebook.JSONobject" Any idea
I don't know how a Facebook.JSONobject works - maybe wallItem.Dictionary["actions"].Array[0].Dictionary["name"]?
Maybe a (wallItem.Dictionary["actions"])["name"] would help. Cast if necessary...
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.