Standard format string json

Now more and more projects and will support the development of plug-ins by default and use the json data format, data retention as a way of transmission. 
He said to be one, would indicate there are a lot of other formats. For example: at most xml. webservice standard data format. 
However, because json is JavaScript Object Notation (JavaScript Object Notation), born on js support is very good, 
so now a lot of ajax so the use of json, it will be better to deal with some.

1. Definitions

What is JSON?
1.JSON refers JavaScript Object Notation (JavaScript Object Notation)
2.JSON is a lightweight text data interchange format
3.JSON language independent *
4.JSON self-descriptive better understood
* JSON syntax to use JavaScript description of data objects, but JSON is still independent of language and platform. JSON parser and JSON library supports many different programming languages.
w3c standard as follows:
the JSON (the JavaScript Object Notation) is a lightweight data-interchange format. Easy to read and write. It is easy for machines to parse and generate. It is based on JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999 a subset. JSON with fully independent of the language of the text format, but also used language similar to C family habits (including C, C ++, C #, Java, JavaScript, Perl, Python , etc.). These properties make JSON an ideal data-interchange language.

JSON construct the two structures to:

1. "Name / Value" is set to (A collection of name / value pairs ). Different languages, it is understood as an object (Object), the record (Record), structure (struct), dictionary (Dictionary), the hash table (hash table), with a list of keys (keyed list), or associative array (associative array).
2. The value of an ordered list (An ordered list of values). In most languages, it is understood as an array (array).
These are common data structures. Virtually all modern programming languages support them in some form. This enables a data format based on the same programming language between these structures exchange possible.

JSON has the following form:

The object is an unordered "name / value pairs" collection. An object to "{" (left bracket) starts, "}" (right parenthesis) ends. Each "name" followed by a ":" (colon); "" name / value pairs "used between", "(comma).

Note: If the background passing objects directly to js, ​​is json format. Reference article:

[ Jquery data to the background + foreground ASP.NET parsing approach described js ]
[ jQuery Ajax passing objects (array) to the background and analytical achieved ]

An array is an ordered set of values (value) of. An array of "[" (left bracket) to start, "]" (right bracket) end. Use between value "," (comma).




Note: The data transfer like to understand. In fact, it is a array. json array and direct relationship, please refer to the article: 

[something about javascript objects and an array of json description] 

2, json standard: 

json said: I do not have standards. Haha. I'm talking about standards refer to what kind of format can be parsed into a string js json? 

The following json string is correct:

 

Copy the code code is as follows:

{
    "employees": [
        {
            "firstName": "Bill",
            "lastName": "Gates"
        },
        {
            "firstName": "George",
            "lastName": "Bush"
        },
        {
            "firstName": "Thomas",
            "lastName": "Carter"
        }
    ]
}

 

note:

json string in js are parsed into objects. Wherein the name of the object, such as:
the Employees, firstName, in "" or '' due to the job. The latter value, if it is int and bool (js is not case-oh), you can not '' or '' cause, the other strings must be quoted, especially cause to remember the date and time!

Summarized as follows:

Which is an object, if a plurality of objects, es, i.e. {}, {}, so that the composition of a sequence of objects, to identify the beginning and end, you need to add [] to be passed, the actual should be transmitted in the form of [{}, {}], if the object is a long pass, the {} form it. Then there is the expression of object attributes, the attribute must be in the ""
between the inside and the attribute values: separated with each attribute to separate, if the property is an array, then use [] comprises up, so the actual transfer of the data format may be: 1, { "attribute 1": a value 1, "attribute 2": 2} value, if the value is a string, it is also needed "" enclosed (below). 2, { "Attribute 1": a value 1, "Attribute 2": [value 1, value 2]}, where the property is an array 2, contains
the value 1 and the value 2.3, { "Attribute 1": a value 1 "attribute 2": { "attribute a ': the value of a" property B ": [value B, the value c]}}, the more complicated, the attribute 2 is an object that the containing attribute a and attribute B, b property is an array containing values and b values, c. I think these should be the most basic, the rest is just to expand on this basis.

In practice, the object to be serialized, as long as the call Newtonsoft.Json.JavaConvert.SerializeObject in .net (); function to

reference:

Jquery ajax achieve transfer objects (an array) to the background and analytical 

http://www.jb51.net/article/40131.htm

3, json there are so many requirements (in fact, not much), how we judge its correctness?

There are ways that you print out the string, about his correspondence in accordance with the above structure, or directly using the online test tool test.

Reference: http://www.kjson.com/  
http://tool.oschina.net/codeformat/json

Guess you like

Origin www.cnblogs.com/lgj8/p/12325466.html