views:

413

answers:

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?

+1  A: 

Hey,

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

HTH.

Brian
Thank you for your response.I use the similar method as described herehttp://stackoverflow.com/questions/401756/parsing-json-using-json-netBut, in my case I can't define "135395949809348" object.
Boris
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.
Brian
A: 

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...

rarouš