HTML and CSS Reference
In-Depth Information
2. Arrays , which are denoted by [] brackets, and contain comma separated values just like
JavaScript arrays.
3. Literal values (strings, numbers, Booleans)
An object or an array can in turn contain any of these 3 types. For instance, an array may
contain an object, an object may contain an array, an object may contain another object,
etc.
JavaScript makes it possible to convert from a stringified version to an object representa-
tion purely because the language does not rely on classes. The stringified version of the ob-
ject does not contain information on what type it is: it is simply a set of properties formatted
according to the JSON specification. Likewise though, JavaScript does not need to know
what type of object needs to be created when de-serializing: it can simply add the appropri-
ate properties to an otherwise empty object.
JSON has become a widely used data format even for applications that do not use
JavaScript. For instance, Java contains libraries for converting to and from JSON. The only
difference in languages such as Java is that you must tell the library what type of class the
textual string represents.
//
Java can in fact de-serialize a string into an object without knowing the type, but
it needs to use hash maps rather than programmer defined types.
One reason for the widespread adoption of JSON (beyond its simplicity) is the fact it is far
less verbose than XML - the example above is roughly half the size of the XML version.
Although the size is far smaller, it is still easy for a human to read and understand a JSON
encoded message (which was a traditional strength XML had over other data formats, par-
ticularly binary data formats).
As we go through the topic we will explore several cases where this ability to convert
simply and easily from an object to a textual string is enormously useful.
 
Search WWH ::




Custom Search