Consuming iusethis JSON data with javascript

| Comments (0)

JSON is short for Javascript Object Notation, and it's a cross-language data representation standard, which also happens to be native javascript. This makes it really easy to process this data on the client side, either as a XMLHTTPRequest, or if you want to use it cross-domain, you can use a callback function and a javascript include node.


That makes it easy to generate dynamic html from iusethis data on the client-side. First we define a function to output data:

function fill_node(data) {
    $('iusethis').innerHTML='<p><img src="'+data.app.icon+'"/> '+
        data.app.name+' used by '+data.app.usecount+' people.</p>';
}

Note that the $() function is a common function provided by several javascript frameworks as an alias for document.getElementById . And yes, I know this pretty quick and dirty, but it serves ok as an example of using JSON data.

Now all that remains is to load the JSON and make it call your function.

<script type="text/javascript"
 src="http://osx.iusethis.com/json/iterm?callback=fill_node"></script>

And presto, you have dynamically updated content on your website, without any serverside requirements at all.

For reference, Here is an overview of the data return in the app object:

universal:
1 for apps that work on powerpc and intel, 0 otherwise
icon:
URL to the app icon
version:
Version number of the latest release
name:
The full name of the app
description:
The description of the software from iusethis
license:
The license of the software
tags:
An array of the tags given to the app
homepage:
URL to the home page of the app
short
The URI identifier of the app
user_count:
Number of users of the app on iusethis
download
Link to download the app
screenshot
URL to a screenshot of the app

Leave a comment

About this Entry

This page contains a single entry by Marcus published on August 11, 2007 8:09 PM.

Our Developer APIs was the previous entry in this blog.

AOTW: TaskPaper is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.2rc1-en