0

I want to parse data on client side, I am keeping data in input field after serialization.

JavaScriptSerializer objJavaScriptSerializer = new JavaScriptSerializer();
string jsonString = objJavaScriptSerializer.Serialize(_statusVal);
jsonFmtStatusValue.Value = jsonString;

On Client Side When I saw the data string which is stored in input field it's coming like this

[
    {
        "nodeContentId": "1234_5678",
        "statusTypeId": "5678",
        "statusName": "Submitted by Customer",
        "dateTime": "/Date(1352745000000)/",
        "forceEmail": "on",
        "user": {
            "userId": "0",
            "userName": "admin"
        },
        "note": {
            "typeName": null,
            "dataValue": null
        }
    },
    {
        "nodeContentId": "1234_5678",
        "statusTypeId": "5678",
        "statusName": "Checked, Printed, Folded & Re-checked",
        "dateTime": "/Date(1353402060000)/",
        "forceEmail": "on",
        "user": {
            "userId": "0",
            "userName": "admin"
        },
        "note": {
            "typeName": null,
            "dataValue": null
        }
    }
]

Code Which I tried to parse Json data is :

    var JsonData = $("#<%=jsonFmtStatusValue.ClientID %>").val();
    obj = jQuery.parseJSON(JsonData)
    alert(obj.nodeContentId);

Things I get in alert box: Undefine

Not able to figure out what should i use for parsing.

1
  • @pst: He quoted his code doing the parsing, that part's fine. Commented Nov 24, 2012 at 11:34

1 Answer 1

4

(Note: I'm assuming that jsonFmtStatusValue ends up being an input or textarea on the page.)

In your alert(obj.nodeContentId);, obj is the array, not an object in the array. Your outermost JSON entity is an array, which then contains objects.

You can see the first nodeContentId like this:

alert(obj[0].nodeContentId);

...and of course the others are at subsequent indexes, so for instance:

var obj = jQuery.parseJSON(JsonData);
var n;
for (n = 0; n < obj.length; ++n) {
    alert("obj[" + n + "].nodeContentId = " + obj[n].nodeContentId);
}
Sign up to request clarification or add additional context in comments.

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.