rksh rksh - 1 year ago 86
Javascript Question

Jquery JSON decode multiple arrays

I have this multiple set of data as array

data = [{"id": "1", "name" : "abc", "key1" : "value12 }, {"id": "2", "name" : "cde", "key2" : "value2" }.....]

I need to get this data using jQuery

json = $.parseJSON(data);

but how do I access the parsed JSON data?
shows the result as undefined.


Update : Sorry I fixed the above example JSON I gave, I just quickly typed it by myself and it's not the original json I'm having trouble with. I just gave it to give an idea about the problem that I was having. Thanks for the answers :)


It isn't JSON. It isn't even JavaScript.

If you fix the syntax errors (such as the missing quotes and the missing commas between the array items) then it is an array literal (containing object literals which contain …). Don't parseJSON it (you use that on JSON texts stored in JavaScript strings).

Since it is an array. It doesn't have an id. It has a number of numerical indexes.

var someObject = data[0];

The objects stored on those indexes have ids.

var id = someObject.id;