Time for action – getting JSON data
Now let's do the same thing as we did in the previous section, except that we will get the data from a file containing JSON formatted data rather than XML. The concept is the same, except that what we get back from the Ajax call is a JavaScript object rather than an XML document. You can find the code for this example in Chapter 8/example8.2
.
First let's define our JSON file, which we will name weather.json
, and put it in the data
folder:
{ "location": { "city":"Your City" } ,"current_observation": { "weather":"Clear", "temperature_string":"38.3 F (3.5 C)", "wind_string":"From the WSW at 1.0 MPH Gusting to 5.0 MPH", "feelslike_string":"38 F (3 C)", "relative_humidity":"71%", "icon_url":"images/nt_clear.gif" ...