JSON and json online resolution

Source: Internet
Author: User

JSON and json online resolution


JSON (JavaScript Object Notation) describes data objects using JavaScript syntax, but JSON is still independent of the language and platform. The JSON parser and JSON library support many different programming languages. JSON data can be transmitted using AJAX. The MIME type of JSON text is "application/json ".

 

JSON syntax rules

JSON syntax is a subset of the syntax of JavaScript Object Notation.

L data in name/value pairs

L data is separated by commas (,).

L brackets save objects

L square brackets Save the Array

 

The JSON value can be:

L number (integer or floating point number)

L string (in double quotation marks)

L logical value (true or false)

L Array (in square brackets)

L object (in curly brackets)

L null

 

JSON example

var txt = '{"employees" : [' +'{"firstName":"Bill" , "lastName":"Gates"},' +'{"firstName":"George" ,"lastName":"Bush" },' +'{"firstName":"Thomas" ,"lastName":"Carter" } ]}';

 

Because the JSON syntax is a subset of JavaScript syntax, the JavaScript function eval () can be used to convert JSON text to JavaScript objects.

 

The eval () function uses a JavaScript compiler that parses JSON text and generates JavaScript objects. Text must be enclosed in parentheses to avoid syntax errors:

var obj = eval("(" + txt + ")");

You can also directly create a JSON object:

var  jsonObject ={"manager":"Tom","employees": [      { "firstName":"Bill" ,"lastName":"Gates" },      { "firstName":"George" ,"lastName":"Bush" },      { "firstName":"Thomas" ,"lastName":"Carter" }      ]}

Obtain data in JSON:

Get the manager name: jsonObject. manager

Obtain the name of the second employee: jsonObject. Employees [1]. lastName

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.