0

I am using "JavaScriptSerializer" to Deserialize a Json string. This Json string contains collection of array like

{ "data": [
    // **
    { "id": "1234",
      "from": {
        "name": "abc",
        "id": "000041"
      },
      "message": "user message",
      "updated_time": "2011-10-06T10:14:18+0000",
      "likes": {
        "data": [
          { "id": "94387930",
            "name": "XXXX"
          }
        ]
      },
      "comments": {
        "data": [
          { "id": "7127141",
            "from": {
              "name": "YYYYY",
              "id": "888888"
            },
            "message": "comment message",
            "created_time": "2011-10-06T10:20:44+0000"
          }
        ]
      }
    }
    // **
  ]
}

The section surrounded by ** is repeated N times. Please help me figure out how to deserialize this JSON.

Thanks

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
iphonedev23
  • 991
  • 2
  • 12
  • 24
  • I don't see anything wrong with this output, it looks like a proper JSON/JavaScript object. What are you exactly trying to do? – Miljenko Barbir Oct 19 '11 at 05:11
  • Yes this is a proper JSON. As mentioned above the section within ** is repeated more than one time. its look like collection of array.I am facing problem in JavaScriptSerializer Deserialization. Give me some idea to Deserialization using JavaScriptSerializer as Deserializer doesn't accept Array type object. – iphonedev23 Oct 19 '11 at 05:27

1 Answers1

0

I'm not sure what do you mean by "deserialize", but you can use this object straight on, for example:

var jData = {...your json...};
for(var i = 0; i < jData.data.length; i++)
{
    document.write(jData.data[i].id + '<br />');
}

Check out this fiddle for full example:

http://jsfiddle.net/nJ369/1/

If you wish to parse the JSON output from ASP.Net code-behind, you could use a JSON parsing library like JSON.NET, or any listed on the official JSON website under C#.

Miljenko Barbir
  • 1,193
  • 1
  • 11
  • 32