Web Development with jQuery®

(Elliott) #1

Making a Server Request (^) ❘ 191


FIGURE 7-2


{


"name" : "Canada",
"iso2" : "CA",
"iso3" : "CAN",
"label" : "Province",
"states" : {
"0" : " ",
"66" : "Alberta",
"67" : "British Columbia",
"68" : "Manitoba",
"69" : "Newfoundland",
"70" : "New Brunswick",
"71" : "Nova Scotia",
"72" : "Northwest Territories",
"73" : "Nunavut",
"74" : "Ontario",
"75" : "Prince Edward Island",
"76" : "Quebec",
"77" : "Saskatchewan",
"78" : "Yukon Territory"
}
}

As you can see, the JSON format uses object literal syntax that you’re already familiar with in


JavaScript. The whole object is wrapped in curly braces but isn’t assigned a name, which makes it


easy for frameworks such as jQuery to take the JSON-formatted data and assign it directly to an


object. In the JavaScript, the preceding JSON was passed to the event handler for the $.getJSON()


http://www.it-ebooks.info

Free download pdf