Chapter: Internet & World Wide Web HOW TO PROGRAM - The Ajax Client - JavaScript: Objects

| Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail |

Using JSON to Represent Objects

In 1999, JSON (JavaScript Object Notation)—a simple way to represent JavaScript objects as strings—was introduced as an alternative to XML as a data-exchange technique.

Using JSON to Represent Objects

 

In 1999, JSON (JavaScript Object Notation)—a simple way to represent JavaScript objects as strings—was introduced as an alternative to XML as a data-exchange technique. JSON has gained acclaim due to its simple format, making objects easy to read, create and parse. Each JSON object is represented as a list of property names and values contained in curly braces, in the following format:

 

{ propertyName1 : value1, propertyName2 : value2 }

 

Arrays are represented in JSON with square brackets in the following format:

 

[ value1, value2, value3 ]

 

Each value can be a string, a number, a JSON object, true, false or null. To appreciate the simplicity of JSON data, examine this representation of an array of address-book en-tries from Chapter 15:

 

[ { first: 'Cheryl', last: 'Black' },

 

{ first: 'James', last: 'Blue' }, { first: 'Mike', last: 'Brown' }, { first: 'Meg', last: 'Gold' } ]

 

JSON provides a straightforward way to manipulate objects in JavaScript, and many other programming languages now support this format. In addition to simplifying object creation, JSON allows programs to extract data easily and to efficiently transmit data across the Internet. JSON integrates especially well with Ajax applications, discussed in Chapter 15. See Section 15.7 for a more detailed discussion of JSON, as well as an Ajax-specific example. For more information on JSON, visit our JSON Resource Center at www.deitel.com/json.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.