My first attempt at it, and the testing function does not seem to work:
$.getJSON('questions.json', function(data) {alert(data);})
I am trying to alert all the contents of the JSON file which is really short.
What am I doing wrong? and why am I getting [object Object]
JSON is a way of encoding an object as a string so that it can be passed around a network easily. When jQuery receives a string containing JSON data, it deserializes it — it turns it back into a Javascript object. This object is passed to your success handler — you’re calling it
data.When you try to
alerta Javascript object, it will give you[object Object], rather than a readable form.You should use a Javascript console as provided by your browser to debug data like this, with the
console.logmethod.