Introduction:
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript programming language, standard ECMA-262 3rd edition-December 1999. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make JSON an ideal data exchange language.
JSON is constructed in two structures:
- A collection of name/value pairs ). In different languages, it is understoodObject), Record, structure (struct), Dictionary, hash table, keyed list, or associative array ).
- An ordered list of values ). In most languages, it is understood as an array ).
Advantages:
When reading data, you can directly transmit JSON objects from the backend. For example, the data source of the Grid Control of ext can be JSON, or XML. However, compared with JSON, data is simpler and the data size transmitted is smaller than XML. When using these applications, we can use json.net to easily convert objects in. Net into JSON strings. Then it is passed to the previous section for calling.
Example:
Javascriptconvert. serializeobject: converts an object to a josn string
Productproduct = newproduct ();
product.Name ="Apple";
product.Expiry =newDateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes =newstring[] {"Small","Medium","Large"};
string json = JavaScriptConvert.SerializeObject(product);
Newtonsoft. JSON. javascriptconvert. deserializeobject: deserializes the object based on the JSON string.
ProductdeserializedProduct = (Product)JavaScriptConvert.DeserializeObject(output,typeof(Product));
The output is a JSON string, and the product is a class object to be deserialized.
Through these two common methods, you can easily get the object from the JSON string and get the JSON string from the object.