.JSON

JSON

JSON full process:

JavaScript Object Notation ( J ava S *script O bject Notation *)

JSON features:

  • JSON is a lightweight text data interchange format
  • JSON is language independent: JSON uses Javascript syntax to describe data objects, but JSON remains language and platform independent. JSON parsers and JSON libraries support many different programming languages. Currently, many dynamic (PHP, JSP, .NET) programming languages ​​support JSON.
  • JSON is self-describing and easier to understand

JSON syntax rules: (JSON syntax is a subset of JavaScript object representation syntax)

  • Data is in name/value pairs
  • Data is separated by commas ,
  • Use slash * * to escape characters
  • Braces {} save objects
  • Square brackets [] save an array, which can contain multiple objects.

Two structures of JSON:

1. Object: The object saved by curly brackets {} is an unordered collection of name/value pairs. An object starts with a left bracket { and ends with a right bracket } . Each "key" is followed by a colon : and name/value pairs are separated by commas .

**2. Array: **The array saved in square brackets [] is an ordered collection of values. An array starts with a left bracket [ , ends with a right bracket ] , and uses commas to separate values .

Value can be a string, number, true, false, null, object or array enclosed in double quotes, and they can be nested.

JSON name/value pairs

The writing format of JSON data is:

key : value
	=	"name" : "lvsure"

JSON value

JSON values ​​can be:

  • Number (integer or float)
  • String (in double quotes)
  • logical value (true or false)
  • Array (in square brackets)
  • object (in curly braces)
  • null

JSON numbers:

JSON numbers can be integers or floats:

"age" = "23"

JSON object:

JSON objects are written within curly braces {} :

{key1 : value1, key2 : value2, ... keyN : valueN }

An object can contain multiple name/value pairs:

{"name = "lvsure", "url" = "https://blog.csdn.net/weixin_43925768?spm=1000.2115.3001.5343"}

JSON array:

JSON arrays are written in square brackets [] :

Arrays can contain multiple objects:

[
    { key1 : value1-1 , key2:value1-2 }, 
    { key1 : value2-1 , key2:value2-2 }, 
    { key1 : value3-1 , key2:value3-2 }, 
    ...
    { key1 : valueN-1 , key2:valueN-2 }, 
]

{
    "sites": [
        { "name":"lvsure" , "url":"https://blog.csdn.net/weixin_43925768?spm=1000.2115.3001.5343" }, 
        { "name":"google" , "url":"www.google.com" }, 
        { "name":"微博" , "url":"www.weibo.com" }
    ]
}

JSON Null

JSON can set null value:

{ "name" : null }

Guess you like

Origin blog.csdn.net/weixin_43925768/article/details/132277922