JSON.stringify与JSON.parse

 

JSON.stringify(value [, replacer] [, space]) 

  Used to convert object --> JSON string.
  1. value : object, array, class
  2. replacer:
    When the array: value exists, then the value of the second parameter is used as the key, and the value of the first parameter is represented by the value. If it does not exist, it is ignored.
    Method: Pass each serialized object (remember each one) into the method for processing.
    3. space : Separator. If not, it will be output directly; if it is a number, it will define a few characters of indentation; the escape character \t means carriage return
 
Function :
  For example, the background data returns: {"code": -1, "msg": "System exception"}
  Without stringify, display: [object, object]
 

JSON.parse():

  string --> json object

  var str = '{ "name":"huangxiaojian","age":23}'
  transform into
  {
    name: 'huangxiaojian',
    age: 23
  }

Guess you like

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