| JSON Posted by: Jordan in Programming, JSON, JavaScript, Feedparser on Jun 22, 2008 |
What does JSON stand for?
JavaScript Object Notation What is it? JSON is the successor of XML and, put simply, is just an organized data structure used for exchanging information. JSON uses objects to pass around this data and looks like this:
var myJSON = { "City" : "New York", "State" : "New York", "zip" : "29432" };
Using the Data in JSON
To access the data in the above JSON object use dot notation (Object Name property). IE:
alert(myJSON.State);
Receiving Data from External Sites/Domains
The concept is simple. You include the URL of the site/feed using the DOM method I described here:Include a JavaScript file from a JavaScript file. Once the external information has been loaded a callback function is executed. Here is what a JSON feed URL would look like:
http://www.domain.com/external.php?type=JSON&callback=startJSON
The callback string tells your script to execute a function named startJSON when the information has finished loading. Here is a sample script to load an external data source:
function loadJSON(url) {
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = url;
headID.appendChild(newScript);
}
Soon I'll write a tutorial on it in our forum and update this blog with the URL. If you have any questions feel free to ask!
Can't wait to see the tutorial.