Notes from Learning Is Every Thing session on JSON held on 16 July 2010.

The session gives an introduction to JSON, its advantages, how to consume JSON services and how it stacks up against XML.

LIET - JSON

Here’s the code from hands-on session on consuming flickr’s api to explore interesting pictures:

<html>
  <header>
    <title>intersting pics</title>
  </header>
  <body>
    <script type="text/javascript" >
      function jsonFlickrApi(list) {
        for(i = 0; i< 10; i++) {
        j = Math.floor(Math.random()*100);
        document.write("<br>");
        document.write(list.photos.photo[j].title);
        document.write("<br>");
        document.write("<img src=\"http://farm");
        document.write(+list.photos.photo[j].farm+".static.flickr.com/"+list.photos.photo[j].server+""+list.photos.photo[j].id+"_"+list.photos.photo[j].secret);
        document.write(".jpg\" >");
        document.write("<br><br><br>");
        }
      }
    </script>
    <script type="text/javascript" src="http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&format=json&api_key=your_api_key" >
    </script>
  </body>
</html>

You’ll have to replace the api_key with a valid one.