Java Reference
In-Depth Information
simple Values
You can represent simple values like strings, numbers, booleans, and null . For example, the
following line is valid JSON:
"JavaScript"
This JSON represents the string value of "JavaScript" , and it looks exactly like a normal JavaScript
string. But there's a big difference between strings in JavaScript and JSON; JSON strings must use
double quotes. Thus, the following is invalid JSON:
'JavaScript'
Numeric data is represented by what appears to be number literals, like this:
10
This is valid JSON representing the number 10. Similarly, boolean values and null look like
JavaScript literals, too:
true
null
objects
Objects in JSON are represented with what looks like JavaScript's object literal notation. For
example, the following is a JavaScript object that represents the same person from earlier:
var person = {
firstName: "John",
lastName: "Doe",
age: 30
};
The JSON representation of this object looks similar. Here is the same object represented in JSON:
{
"firstName": "John",
"lastName": "Doe",
"age": 30
}
A few noticeable differences exist between the JavaScript and JSON representations of this object. First,
JSON doesn't have the person variable name. Remember that JSON is a data format, not a language.
It has no variables, functions, or methods. It simply defines the structure and data of an object.
The second difference is the object's property names. Notice that they are surrounded by double
quotes. In JSON, an object's property names are strings, and the values of those properties follow
the rules specified in the previous section. Double quotes surround the string values of "John" and
"Doe" , and the number 30 appears as a literal value.
 
Search WWH ::




Custom Search