JSON JSON

JSON

JSON ( JavaScript  Object Notation, JS Object Notation) is a lightweight data interchange format. It is based on   a subset of ECMAScript (the js specification developed by the European Computer Association) and uses a text format that is completely independent of the programming language to store and represent data. Concise and clear hierarchy makes JSON an ideal data exchange language. It is easy for humans to read and write, but also easy for machines to parse and generate, and effectively improve network transmission efficiency

JSON syntax rules

In the JS language, everything is an object. Therefore, any supported type can be represented by JSON, such as strings, numbers, objects, arrays, etc. But objects and arrays are two special and commonly used types:
  • Objects are represented as key-value pairs
  • Data is separated by commas
  • Curly braces hold the object
  • Square brackets hold arrays
  • JSON key/value pair

    JSON key-value pair is a way to save JS objects, and it is similar to the way of writing JS objects. The key name in the key/value pair combination is written in front and wrapped in double quotes "", separated by colon :, and then followed by value:
    1
    {"firstName": "Json"}
    This is easy to understand and is equivalent to this JavaScript statement:
    1
    {firstName : "Json"}

    The relationship between JSON and JS objects

    Many people don't understand the relationship between JSON and Js objects, and they don't even know who is who. In fact, it can be understood as follows:
    JSON is a string representation of JS objects, which uses text to represent the information of a JS object, which is essentially a string.
    Such as
    1
    var  obj = {a:  'Hello' , b:  'World' };  //这是一个对象,注意键名也是可以使用引号包裹的
    1
    var  json =  '{"a": "Hello", "b": "World"}' //这是一个 JSON 字符串,本质是一个字符串

    Convert JSON and JS objects

    To convert from an object to a JSON string, use the JSON.stringify() method:
    1
    var  json = JSON.stringify({a:  'Hello' , b:  'World' });  //结果是 '{"a": "Hello", "b": "World"}'
    To convert from JSON to object, use the JSON.parse() method:
    1
    var  obj = JSON.parse( '{"a": "Hello", "b": "World"}' );  //结果是 {a: 'Hello', b: 'World'}

JSON ( JavaScript  Object Notation, JS Object Notation) is a lightweight data interchange format. It is based on   a subset of ECMAScript (the js specification developed by the European Computer Association) and uses a text format that is completely independent of the programming language to store and represent data. Concise and clear hierarchy makes JSON an ideal data exchange language. It is easy for humans to read and write, but also easy for machines to parse and generate, and effectively improve network transmission efficiency

JSON syntax rules

In the JS language, everything is an object. Therefore, any supported type can be represented by JSON, such as strings, numbers, objects, arrays, etc. But objects and arrays are two special and commonly used types:
  • Objects are represented as key-value pairs
  • Data is separated by commas
  • Curly braces hold the object
  • Square brackets hold arrays
  • JSON key/value pair

    JSON key-value pair is a way to save JS objects, and it is similar to the way of writing JS objects. The key name in the key/value pair combination is written in front and wrapped in double quotes "", separated by colon :, and then followed by value:
    1
    {"firstName": "Json"}
    This is easy to understand and is equivalent to this JavaScript statement:
    1
    {firstName : "Json"}

    The relationship between JSON and JS objects

    Many people don't understand the relationship between JSON and Js objects, and they don't even know who is who. In fact, it can be understood as follows:
    JSON is a string representation of JS objects, which uses text to represent the information of a JS object, which is essentially a string.
    Such as
    1
    var  obj = {a:  'Hello' , b:  'World' };  //这是一个对象,注意键名也是可以使用引号包裹的
    1
    var  json =  '{"a": "Hello", "b": "World"}' //这是一个 JSON 字符串,本质是一个字符串

    Convert JSON and JS objects

    To convert from an object to a JSON string, use the JSON.stringify() method:
    1
    var  json = JSON.stringify({a:  'Hello' , b:  'World' });  //结果是 '{"a": "Hello", "b": "World"}'
    To convert from JSON to object, use the JSON.parse() method:
    1
    var  obj = JSON.parse( '{"a": "Hello", "b": "World"}' );  //结果是 {a: 'Hello', b: 'World'}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324786500&siteId=291194637