JSON

JavaScript Object Notation or JSON for short. JSON is smaller than xml and faster and easier to parse. Parsing JSON can be done with .getJSON

$getJSON("path to the json file",function (data)){
 // do something
}

I have used JSON to create slideshows and its good to use because if you a slideshow with multiple images the json file can be called as the image is requested. I would not use this unless your image request is more than a few.

Many API’s now have a JSON format which is much easier to work with. I will create a function to get the current temperature in Seattle, WA.

First, I would like to use an open source Weather API. http://openweathermap.org/

Second, I have requested an api and now I will create a js function to call the JSON every ten minutes.

$(function() {
    getTemp();
});
function getTemp() {
    $.getJSON("http://api.openweathermap.org/data/2.5/weather?q=seattle,usa&units=imperial&APPID=YOURAPPID", function(data) {
		var main = data.main,
		temp = main.temp;
		$('#temp').html(temp + ' °F');
    });
    setTimeout("getTemp()",600000);
}

Current tempture in Seattle, WA

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.