The JSON.parse () configured to parse a string from json objects, such as
var str = '{"name":"Wu","age":"20"}'
JSON.parse(str);
//结果为一个Object
// age: "20";
// name: "Wu";
The JSON.stringify () to parse the string from an object, such as
var a = {age:1,name:"Wu"};
JSON.stringify(a);
//结果为 "{"age":1,"name":"Wu"}"
The reason being given:
because you want to convert the data originally object, this method is to parse a string json object, you will then convert error;
Why is there such a mistake:
Because the Object as a parameter passed JSON.parse () where it will default into the Object string,
it will first call the toString () method on the prototype; the result of "[object Object] is ", JSON.parse the first character '[' understood as the beginning of the array, the second character 'o' does not know how to deal with; so I threw out the error message above Unexpected token o in JSON at position 1