Parsing Facebook Open Graph API JSON Response in C#
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?
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...
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
精彩评论