Home >Web Front-end >JS Tutorial >jQuery.parseJSON(json) converts JSON string into js object_jquery
Overview
Accepts a JSON string and returns the parsed object.
Passing in a malformed JSON string will throw an exception. For example, the following are malformed JSON strings:
{test: 1} (test is not surrounded by double quotes)
{'test': 1} (used single quotes instead of double quotes)
In addition, if you pass in nothing, or an empty string, null or undefined, parseJSON will return null .
Parameters
jsonString
JSON string to parse
Example
Description:
Parse a JSON string
jQuery code:
var str = '{"name":"John"}'; var obj = jQuery.parseJSON(str); alert( obj.name === "John" );