Jquery.parsejson of json converts a json string into a js object
- 2020-03-30 03:35:12
- OfStack
An overview of the
Accept a JSON string and return the parsed object.
Passing in a deformed JSON string throws an exception. For example, the following are all deformed JSON strings:
{test: 1} (test does not enclose double quotes)
{'test': 1} (single quotes instead of double quotes)
In addition, if you pass nothing in, or an empty string, null, or undefined, parseJSON returns null.
parameter
jsonString
JSON string to parse
The sample
Description:
Parse a JSON string
JQuery code:
var str = '{"name":"John"}';
var obj = jQuery.parseJSON(str);
alert( obj.name === "John" );