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?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Boris
  • 119
  • 2
  • 11

2 Answers2

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

Aleš Roubíček
  • 5,198
  • 27
  • 29
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

bkaid
  • 51,465
  • 22
  • 112
  • 128
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Thank you for your response. I use the similar method as described here http://stackoverflow.com/questions/401756/parsing-json-using-json-net But, in my case I can't define "135395949809348" object. – Boris Jul 14 '10 at 16:49
  • 1
    Right, but you may want to try the Dictionary approach, deserialize it to a dictionary and extract the information that way. Bit of a pain, but this scenario would be handled. – Brian Mains Jul 15 '10 at 11:21