Problem Parsing JSON Result with jQuery
Posted
by senfo
on Stack Overflow
See other posts from Stack Overflow
or by senfo
Published on 2010-04-29T13:52:39Z
Indexed on
2010/04/29
13:57 UTC
Read the original article
Hit count: 377
I am attempting to parse JSON using jQuery and I'm running into issues. In the code below, I'm using a static file, but I've also tested using an actual URL. For some reason, the data keeps coming back as null:
<!DOCTYPE html>
<html>
<head>
<title>JSON Test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$.getJSON('results.json',
function(data) {
alert(data); // Result is always null
});
</script>
</head>
<body>
</body>
</html>
The JSON results look like the following:
{"title":"HEALTHPOINT TYEE CAMPUS","link":"http://www.healthpointchc.org","id":"tag:datawarehouse.hrsa.gov,2010-04-29:/8357","org":"HEALTHPOINT TYEE CAMPUS","address":{"street-address":"4424 S. 188TH St.","locality":"Seatac","region":"Washington","postal-code":"98188-5028"},"tel":"206-444-7746","category":"Service Delivery Site","location":"47.4344818181818 -122.277672727273","update":"2010-04-28T00:00:00-05:00"}
If I replace my URL with the Flickr API URL (http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?), I get back a valid JSON result that I am able to make use of.
I have successfully validated my JSON at JSONLint, so I've run out of ideas as to what I might be doing wrong.
Any thoughts?
© Stack Overflow or respective owner