HTML and CSS Reference
In-Depth Information
JSON is very similar to XML in that it structures data in a hierarchy, but its main difference is that it's really JavaScript
objects that are parsed by the browser natively regardless of an XML manifest. Another benefit with JSON and JSON-P,
is that it doesn't care what domain it's coming from. This means that XML can be crippled in its response if the
domain hosting the information (in this case, Yahoo) wasn't the same as the domain making the request (in this case,
the ad). There are ways around this cross-origin policy, either by using CORS, which you learned about in Chapter 6, or
simply by using JSON-P. Sometimes JSON-P is not an option for a web service's response data format, but if it is, you'll
never need to worry about domain security issues when working with HTML5 ads. In the case of Yahoo's weather
service, making a JSON request is very similar to XML. Listing 11-2 shows the same example using JSON.
Listing 11-2. Yahoo's Weather API JSON Example
"query": {
"count": 1,
"created": "2012-08-01T23:29:00Z",
"lang": "en-US",
"results": {
"channel": {
"title": "Yahoo! Weather - Conshohocken, PA",
"link": "* " ,
"description": "Yahoo! Weather for Conshohocken, PA",
"language": "en-us",
"lastBuildDate": "Wed, 01 Aug 2012 6:53 pm EDT",
"ttl": "60",
"location": {
"city": "Conshohocken",
"country": "US",
"region": "PA"
"units": {
"distance": "mi",
"pressure": "in",
"speed": "mph",
"temperature": "F"
"wind": {
"chill": "72",
"direction": "0",
"speed": "0"
"atmosphere": {
"humidity": "94",
"pressure": "29.85",
Search WWH ::

Custom Search