3

I am using Newtonsoft Json library to parse json but i don't know how to use it. I parsed the string using JObject. When i output the value of JObject instance in immediate window i get this :-

json
{
  "data": [
    {
      "id": "id",
      "from": {
        "name": "name",
        "id": "someotherid"
      },
      "name": "pic",
      "description": "desc",
      "link": "linktosite",
      "privacy": "everyone",
      "count": 1,
      "type": "normal",
      "created_time": "2010-10-22T14:54:32+0000",
      "updated_time": "2010-10-22T14:55:41+0000"
    },
    {
      "id": "id2",
      "from": {
        "name": "name",
        "id": "someotherid"
      },
      "name": "Profile Pictures",
      "link": "link",
      "privacy": "everyone",
      "count": 6,
      "type": "profile",
      "created_time": "2010-10-12T14:27:58+0000",
      "updated_time": "2011-01-01T18:38:14+0000"
    },
    {
      "id": "id3",
      "from": {
        "name": "name",
        "id": "829741958"
      },
      "name": "T",
      "link": "link",
      "privacy": "everyone",
      "count": 5,
      "type": "normal",
      "created_time": "2010-05-01T03:03:39+0000",
      "updated_time": "2010-05-01T03:19:13+0000",
      "comments": {
        "data": [
          {
            "id": "id",
            "from": null,
            "message": "message",
            "created_time": "2010-08-28T18:27:10+0000",
            "likes": 1
          }
        ]
      }
    }
  ],
  "paging": {
    "previous": "paginglink",
    "next": "otherpaginglink"
  }
}

    Count: 2
    Type: Object

What should i do further to have the values from this jobject?

TCM
  • 16,780
  • 43
  • 156
  • 254

1 Answers1

3

I personally prefer the JavaScriptSerializer for use with JSON in the .NET environment. By default it will return a Dictionary result, but can be used to parse in to a custom object (or you could make use of the dynamic datatype).

Some other posts on SO with JSON & JavaScript Serializer as topic

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • Unfortunately i am using Silverlight and in Silverlight there is no JavaScriptSerializer as far as i know. Thanks anyways! – TCM Feb 08 '11 at 15:50
  • @KarCheng: How about the [DataContractJsonSerilizer](http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer%28v=vs.95%29.aspx)? There's a good article from Microsoft [found here](http://msdn.microsoft.com/en-us/library/cc197957%28v=vs.95%29.aspx). – Brad Christie Feb 08 '11 at 15:54
  • Yes DataContractJsonSerializer will work pretty well but i ended up using dynamic keyword available in C# 4.0. – TCM Feb 10 '11 at 03:41
  • @Kar Cheng: Interesting. Would you post your dynamic code? – Pat Apr 07 '11 at 22:53
  • @Anthony Can you post your dynamic code? – Nathan DeWitt Jan 11 '12 at 20:25