JavaScript Editor Free JavaScript Editor     JavaScript Debugger 




Main Page

Previous Page
Next Page

16.2. JSON and JSON-RPC

There's definitely a Greek theme with many of the names involved with using the XMLHttpRequest object. First there is Ajax itself, a legendary hero, followed by Microsoft's version called ATLAS, one of the Titans. Finally, there is JSON, pronounced "Jason," which stands for JavaScript Object Notation.

16.2.1. JavaScript Object Notation

Although I am by no means an expert on the subject, JavaScript Object Notation (JSON) works as a kind of replacement for XML. This might sound a little weird, but it makes perfect sense when viewed from a cross-browser point of view. The reason for this is that more web browsers support JavaScript than XML. This is just another way to distribute applications to as many people as possible.

JSON appears to work something along the lines of children's building blocks. With blocks, a few basic shapes are used in conjunction with imagination to create complex structures. The same can be said of JSON: A few basic "shapes" are used in conjunction with imagination to create complex structures. The only difference is that whereas children's blocks result in physical structures, JSON results in logical structures.

Let's take a look at the two basic data structures (blocks) that are used to create more complex structures in JSON. The first of these basic data structures is the name-value pair, which really isn't anything that we have not already seen in earlier chapters. Just think along the lines of a JavaScript collection or associative array, and you'll be fine.

The second basic data structure in JSON has the formidable description of "an ordered list of values." Ooh, sounds scary. In fact, it sounds a lot scarier than its actual name, array. Say "an ordered list of values," and people will pay attention; say "array," and unless you're talking about an array of missile silos, nobody cares.

These structures, in turn, are used to create somewhat more complex structures. The first of these more complex structures is an object; such objects consist of an unordered list of name-value pairs, with the following syntax for an empty object:

object_name { }

Of course, an empty object isn't very useful, so it is necessary to add members as string-value pairs. Of course, sometimes saying nothing is enough.

That is a high-level (as in, orbital) view of the concepts behind JSON. All we need to look at now is the actual syntax. After all, because the information going back and forth from the web server and the web browser has to be text, an internal representation of a JavaScript array would probably cause some problems when trying to send it to and fro.


Previous Page
Next Page




JavaScript Editor Free JavaScript Editor     JavaScript Debugger


©