Differences between JSON. stringify () and JOSN. parse () methods, stringifyparse
Today, I finally figured out the two methods of JSON. stringify () and JSON. parse (). The following small series will be recorded here!
JSON. tringify (): converts a json data to a JSON string
JSON.stringify({uno:1,dos:2},null,'\t')"{"uno": 1,"dos": 2}"JSON.stringfy({uno:1,dos:2})JSON.stringify({uno:1,dos:2})"{"uno":1,"dos":2}"JSON.stringify({uno:1,dos:2},null,'\n')"{"uno": 1,"dos": 2}"JSON.stringify({uno:1,dos:2},null,'\b')"{"uno": 1,"dos": 2}"JSON.stringify({uno:1,dos:2},null,'\f')"{"uno": 1,"dos": 2}"
JSON. parse (): converts string to json.
JSON.parse('{"a":"a"}');Object {a: "a"} JSON.parse('{"p": 5}', function(k, v) {if (typeof v === 'number') {return v * 2; // return v * 2 for numbers}return v; // return everything else unchanged});// { p: 10 }
See JSON. parse () and JSON. stringify ()
1. parse is used to parse json objects from a string. For example
var str='{"name":"cpf","age":"23"}'
JSON. parse (str:
Object: age:"23" name:"cpf" _proto_:Object
Ps: Each attribute must be enclosed in double quotation marks ({}). Otherwise, an exception is thrown.
2. stringify is used to parse a string from an object, for example
var a={a:1,b:2}
JSON. stringify (:
“{“a”:1,"b":2}”
The above is the JSON file that we will introduce to you. stringify () and JOSN. the parse () method is different and I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!