JSON JAVASCRIPT

Click Here

It is very easy to use JAVASCRIPT to access the values in a JSON object.

For example, given the following object JSON

{"contacts":[ {"firstName":"Adam", "lastName":"Smith"}, {"firstName":"Anne", "lastName":"Davis"}, {"firstName":"Bruce", "lastName":"Harris"}, {"firstName":"David", "lastName":"Lee"} ]}

We convert the JSON object in an JAVASCRIPT object.

var obj = JSON.parse(contacts);

If we enter the field "firstname" the first element:

obj.contacts[0].firstName

The result is:

Adam

We used the value 0 to select the first value of the array. We will use the value 1 for the second element, and so on.


Click Here