Trying to parse json from a site and the site doesn’t have a lot of help yet for their new api so I’m a bit stuck. The json comes back from the site as follows.
I’m not the best person to answer your question as I’ve only looked at jason a bit and jquery a bit more. But hopefully I’ll learn something from your thread.
I’m wondering if it’s a syntax thing. If you try
function check()
{
$.getJSON("sitesjson.json", function(data)
{
alert(data);
});
}
No it says “Null” but when I use the flickr json I get [object object] (what you’d expect to get) which is why I’m wondering is the json file malformed.
What Content-Type does the webserver send for the JSON file?
You can check by inspecting the headers using the HTTP Live Headers plugin for Firefox. I can imagine the server sends something like text/plain. jQuery 1.4 is quite strict and doesn’t accept that AFAIK. It needs application/json I believe.
jQuery < 1.4 don’t really care all that much about the Content-Type I believe (not sure though).
Can you get it to return application/json, or is that out of your hands?
Also, which version of jQuery are you using?
The comment I made about Content-Types doesn’t apply to jQuery versions lower than 1.4, and even for 1.4 I’m not sure if my comment is valid for $.getJSON, since the changelog only mentions that $.get() can now autosense JSON when the returned Content-Type is application/json, when no dataType is given. However, when using $.getJSON() a datatype is given …
I’ll try and look into this a little more tomorrow if I have the time…