JSON Posted by: Jordan in ProgrammingJSONJavaScriptFeedparser on
JSON seems to be a popular term appearing everywhere now. I discovered it while working on CCIT and ran into a Cross Site/Domain AJAX  issue. Well, I had a bit of time today to look into it and I learned quite a bit.

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!

 


Trackback(0)
feed1 Comments
gaylo565
June 22, 2008
Votes: +0

Always good to learn something new smilies/wink.gif Can't wait to see the tutorial.

report abuse
vote down
vote up

Write comment
 
 
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger
 

security image
Write the displayed characters


busy