Section 7.9. Just Do It Solutions


7.9. Just Do It Solutions

Before we discuss how JSON and server-side languages like PHP get along, let's take a closer look at how you can access JSON data in your JavaScript. Here's another JSON data structure:

     {"books": [     {"title":"Hyperion", "author":"Dan Simmons", "isbn":"0553283685"},     {"title":"The Stars My Destination", "author":"Alfred Bester", "isbn:":"0679767800"},     {"title":"Black House", "author": [ "Stephen King", "Peter Straub"],     "isbn":"0345441036"},     {"title":"The Golden Compass", "author":"Philip Pullman", "isbn":"0679879242"}, ]}; 

Below are several values from the JSON structure. Your job is to write the JavaScript code that would return the value from the JSON data structure. You can assume the JSON data is in an object called jsonData.

 Always begin with the JSON data object. "Alfred Bester"                    var bester = jsonData.books[1].author;                                    ________________________________________ "0679879242"                                    var isbn = jsonData.books[3].isbn;                                    ________________________________________ Remember, all these array indices start at 0, not at 1. "0345441036"                                    var isbn2 = jsonData.books[2].isbn;                                    ________________________________________ "Dan Simmons"                                    var simmons = jsonData.books[0].author;                                    ________________________________________ "Black House"                                    var blackHouse = jsonData.books[2].title;                                    ________________________________________ "Peter Straub"                     var straub = jsonData.books[2].author[1];                                    __________________________________________ var straub = jsonDat Remember, all these array indices start at 0, not at 1. 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net