JSON Simple Introduction to _json

Source: Internet
Author: User
Tags arrays eval

JSON Simple introduction:

The so-called JSON is the acronym for JavaScript Object notation, meaning JavaScript objects notation.

Here's a summary of JSON:

(1). JSON refers to the JavaScript Object notation, which is the abbreviation for the JavaScript objects notation.
(2). JSON is a lightweight text data interchange format.
(3). JSON is platform-and language-independent.
(4). JSON is self-describing and very easy to understand.

Special Note: JSON is a syntax for standardizing string data formats.
Code instance:

Example one:

{"WebName": "Cloud-dwelling community", "url": "Jb51.net", "Age": "10"}

Above is a simple JSON format for the content.
Special Note: You must be in the string context to call the JSON content.
Example two:

var strjson= ' {"WebName": "Cloud-dwelling community", "url": "Jb51.net", "Age": "Ten"};
var jsonobj=eval ("(" +strjson+ ")");
Console.log (Jsonobj.webname);

In the code above, use the Eval () function to convert the JSON content to the object's direct amount.

describes
We know that Ajax technology can make each request faster, and for each request it returns not the entire page, but only the data that needs to be returned. Typically, Ajax parses and renders data in XML format through the return of data in the form of HTML, and then through the client's complex JavaScript script.
JSON (read Jason) is designed to make the data format a standard and simpler to be parsed by JavaScript.

Benefits
1, lightweight Data Interchange Format
2, people read and write more easily
3, easy to machine parsing and generating
4, able to parse JSON () function via JavaScript in the eval () 5, JSON supports multiple languages. Includes: actionscript, c, c#, coldfusion, e, java, javascript, ml, objective  CAML, Perl, PHP, Python, Rebol, Ruby, and Lua. 

Syntax
JSON syntax is a protocol used to transmit and generate data, much like the C family language, so it is easy to be resolved by the language of the C family.
Object: Object contained between {}
property: Represented by a key-value pair. Separate the attributes with commas.   string : value 
Arrays: Arrays are stored between []    [ elements ] 
Elements: elements are separated by commas
values: values can be strings, numbers, objects, arrays, True,false,null
Example:

Json
[
{
Name: "Michael",
Email: "17bity@gmail.com",
Homepage: "Http://www.jialing.net"
},
{
Name: "John",
Email: "John@gmail.com",
Homepage: "Http://www.jobn.com"
},
{
Name: "Peggy",
Email: "Peggy@gmail.com",
Homepage: "Http://www.peggy.com"
}
]


In fact, Google Maps did not use XML to pass data, but instead used the JSON scheme.

Another advantage of JSON is "Cross-domain", as you would use in a Web page
<script type= "Text/javascript" src= "Http://www.yyy.com/some.js" >

is entirely feasible, which means that you can pass information across domains. Using XMLHttpRequest does not capture cross-domain information, which is restricted by the security nature of JavaScript.

Can JSON completely replace XML? Of course not, because of the advantages of XML: versatility. It is not easy to produce syntactically qualified JavaScript code on the server side, which occurs primarily in a larger system, with different developers on the server side and the client.

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.