getJSON only returning [object Object],[object Object]
javascript, jquery, json
Solution
please try like this:
$.getJSON("appData.json", function(results) {
$.each(results, function(index) {
alert(results[index].foo);
});
});
Problem
I am testing out some code and I have created a json file with the data. The problem is that I'm getting "[object Object],[object Object]" in the alert. No data. What I'm I doing wrong? Here is the code: ``` <!DOCTYPE HTML> <html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> $(document).ready(function() { $.getJSON("appData.json",function(results){alert(results);}); }); </script> </head> <body> </body> </html> ``` and here is the content of appData.json ``` [{"foo":"bar"},{"foo2":"blablabla"}] ``` Also, The index.html file and the json file are both on my desktop and I am running it from there.