Search code examples
javascriptjsonparsing

How to convert JSON string to javascript objects?


I searched for this topic, and I can't seem to find the right way to parse the JSON string to read the objects.

Here is my code

$.getJSON("<url>", 
function(data) {

alert("success!"+data);

});

outputs:

success![object Object],[object Object],[object Object],[object Object]

Firebug shows correct response, and when I click JSON tab I see all the objects.

Thanks!


Solution

  • JSON = JavaScript Object Notation precisely because it is the way to declare object literals in JavaScript. The data parameter is already a Javascript object (in your case an array of objects) that you can access as:

    data[index].fieldname