PHP/Javascript/HTML Public JSON Data Usage Primer Tutorial

PHP/Javascript/HTML Public JSON Data Usage Primer Tutorial

PHP/Javascript/HTML Public JSON Data Usage Primer Tutorial

Here is a tutorial that introduces you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications.

The two big PHP functions of use are:

The public data for today’s tutorial regarding time zones is derived from data from World Clock Time Zones JSON Data Feeds | GoMashUp. The one stop shop for mashup. JSON, XML, RSS feeds. for which we give thanks.

Another tool you should have in your armoury for jobs like this is the online JSON validator here. It will help show you, as with the case here in this tutorial, that the data emanating from the link you are given may not satisfy json_decode’s expected data format, especially that derived from the use of file_get_contents. The line of code …

$json = substr(str_replace(‘]}’,’]’, str_replace(‘{x[‘,'[‘, str_replace(‘”result”:’,”, str_replace(“)”, “”, str_replace(“?(“,””,$pageContent))))),1);

… is a reflection of massaging the data you might have to make it suitable for json_decode usage. So, in practical terms you should try bare bones file_get_contents and json_decode calls for the URL you were given, and think optimistically, but if you run into trouble …

  1. Type the URL you were given into a web browser address bar and have a look at it
  2. Type the URL you were given into //jsonlint.com/ and have it validated
  3. Understand in your own mind what would be different about 1. to make it suitable
  4. Incorporate findings of 3. into massaging of data between file_get_contents and json_decode

Here is a link to some downloadable PHP programming source code which you may want to rename to time_zones.php

One last tool of interest is the PHP command var_dump which can be useful to display for the variable on the left hand side of your json_decode statement, like var_dump($json_output) in the case of this tutorial.

If this was interesting you may be interested in this too.

This entry was posted in Data Integration, eLearning, Tutorials and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>