2

I try to get parse JSON response for the following link: https://graph.facebook.com/feed/?ids=135395949809348,149531474996&access_token=

The response is like that:

{
   "135395949809348": {
      "data": [
         {
             ....Some data
         }]
     }
,
   "325475509465": {
      "data": [
         {
       ....Some data......
      }]
    }
}

I use System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(string json) method. But the objects key names always different , so I can't define the class that can be used for parsing this response. Is anyone has any experience in parsing multiple id's response from Facebook?

2 Answers 2

3

With JSON.NET you can read the respose as JObject and then access it via indexer.

var json = JObject.Parse(result);
var array = json["325475509465"]["data"];

Then you can deserialize objects from array...

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

Comments

1

What is your issue with the Deserialize? Deserialize is going to produce a Dictionary, with potential inner arrays and dictionary instances too....

It wouldn't parse as a custom object unless you build a serializer to do that... or look at JSON.NET: http://james.newtonking.com/pages/json-net.aspx

2 Comments

Thank you for your response. I use the similar method as described here stackoverflow.com/questions/401756/parsing-json-using-json-net But, in my case I can't define "135395949809348" object.
Right, but you may want to try the Dictionary<string, object> approach, deserialize it to a dictionary and extract the information that way. Bit of a pain, but this scenario would be handled.

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.