Author |
Topic: What's JSON? |
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
What's JSON? |
JSON stands for JavaScript Object Notation. It is a text-based open standard designed for human-readable data interchange, just like LDIF or XML.
|
|
|
|
|
|
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
JSON's Syntax |
JSON's structural characters:
1) {
2) }
3) [
4) ]
5) :
6) ,
JSON's basic types:
1) Number -- 123
2) String -- "abc"
3) Boolean -- true or false
4) Array -- [ <any>, ... ]
5) Object -- { "attrName":<any>, ... }
6) null -- <empty>
|
|
|
|
|
|
|
WebSpider member offline |
|
posts: |
147 |
joined: |
06/29/2006 |
from: |
Seattle, WA |
|
|
|
|
|
JSON Example |
For example, a person's contact information can be represented in JSON as follows:
contact::=
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"married": true,
"address": {
"streetAddress": "123 Main Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"email": [ "jsmith@yahoo.com", "jsmith@gmail.com" ],
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
It can be deserialized into object by JavaScript's eval()
var p = eval("(" + contact + ")");
or JSON's parse()
var p = JSON.parse(contact);
|
|
|
|
|
|
|
|