Investigating into JSON feeds


Budding my newest JSON-based widgets was done with loads of trial and error, lacking a good understanding of the JSON-format and lacking knowledge of how to admission the feed and retrieve the data. So yesterday I did some investigate and developed a small javascript program to examine the feeds. It is tech material, so don't be anxious if you don't understand it.

I establish some documentation on the JSON-feed format, based on Google Calendar. A little later I discovered a simple tutorial on how to browse through JSON objects.

I tainted this into a recursive javascript function, that browses the complete JSON-feed-tree, and displays all keys and all values. You can use is to research any JSON-feed.

Create a simple HTML-page, using the following code.

<html>
<head>
<script type='text/javascript'>
function listkeys(feedobj,depth) {
for (key in feedobj) {
for (var i=0; i<depth; i++) document.write('- ');
document.write(key+' = '+feedobj[key]+'<br/>');
listkeys(feedobj[key],depth+1);}
}

function showfeedcontent(json) {
listkeys(json,0);
}</script>
</head>
<body>
JSON FEED PARSER
<br/><br/>
<script src="http://blognucleus.com/feeds/posts/default?alt=json-in-
script&callback=showfeedcontent"></script>
</body>
</html>

In this code restore the blognucleus.com feed reference to your own blog's feed.


Now open the HTML-page in your browser and the complete feed will be displayed.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

More From Webworld