HTML and CSS Reference
In-Depth Information
EXAMPLE 18.19 ( CONTINUED )
3. Output after the eval().
18.5.3 Putting It All Together with JSON
In the next set of examples, we will create a JSON text file, with the structure of a Java-
Script object (in fact, any program employing hashes or associative arrays could read
this file), use an Ajax program to request the file and, after getting a response from the
server, read and parse the JSON data with JavaScript's eval() function, then place the
parsed data in a div container and display it (shown in Figure 18.20).
The JSON File (ajaxCar.json)
EXAMPLE 18.20
1 { "make":"Honda Civic",
"year":2006,
"price":18000,
2 "owner":{
"name":"Henry Lee",
"cellphone": "222-222-2222",
3
"address":{"street": "10 Main",
"city": "San Francisco",
"state": "CA"
}
},
"dealer": "SF Honda"
4}
EXPLANATION
1
This is a JSON object consisting of properties and their values (key/value pairs).
2
The owner property has nested properties. If the object is named β€œcar”, then to get
the cell phone number for the owner , the dot notation is used to separate the prop-
erties; for example, car.owner.cellphone will get the value β€œ222-222-2222”.
Continues
 
 
Search WWH ::




Custom Search