TanguyB TanguyB - 1 year ago 68
JSON Question

Load a JSON file into a JS object

I try to load a json file into a JavaScript var but it just doesn't work out.

var jsonString = JSON.stringify('./test.json');
var obj = JSON.parse(jsonString);


it says that it can't read property ProductID of undefined.

What am I doing wrong here ?

Answer Source

You need to make an AJAX call to get the file. $.getJSON was intended for exactly this purpose:

$.getJSON('./test.json', function(obj) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download