go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  JSON Example
 
Subject: JSON Example
Author: WebSpider
In response to: JSON's Syntax
Posted on: 09/21/2013 06:42:01 PM

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);



 

> On 09/21/2013 06:35:14 PM WebSpider wrote:

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>






References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.