0

I have to retrieve specific value from json. Ex: "id": "217331368373746" in string formate. below is the json query and my code to acess id=217331368373746

{
   "id": "191746304265586",
   "albums": {
      "data": [
         {
            "id": "217331368373746",
            "created_time": "2012-03-24T20:53:34+0000"
         }
      ],
      "paging": {
         "next": "https://graph.facebook.com/191746304265586/albums?limit=1&fields=id&after=MjE3MzMxMzY4MzczNzQ2"
      }
   }
}

CODE:

var jsonalbum = Retrivedata("https://graph.facebook.com/191746304265586?fields=albums.limit(1).fields(id)");
        foreach (var objalbum in jsonalbum["albums"])
        {
            //here what code
        }

    public dynamic Retrivedata(string query)
    {
        var request = WebRequest.Create(query);
        var twitpicResponse = (HttpWebResponse)request.GetResponse();
        var reader = new StreamReader(twitpicResponse.GetResponseStream());
        JavaScriptSerializer js = new JavaScriptSerializer();
        return js.Deserialize<dynamic>(reader.ReadToEnd());
    }

2 Answers 2

1

Looks like

foreach (var objalbum in jsonalbum["albums"]["data"])
{
   var id = objalbum["id"]
}
Sign up to request clarification or add additional context in comments.

Comments

0

Looks like you also have a data property (array) inside your albums list so you would have to do:

foreach (var objalbum in jsonalbum["albums"]["data"])
{
   var id = objalbum["id"];
   ...
}

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.