jQuery.parseJSON () method
Examples
Parse a JSON string
$ (Function () {
var . obj = jQuery parseJSON ( '{ "name": "John"}'); alert ( obj. name === "John" );})
try it"
Definition and Usage
JSON string $ .parseJSON () function is used to match the standard format into the corresponding JavaScript object.
Note: Incoming malformed JSON string may result in an exception. For example, the following invalid JSON string:
"{test: 1}" //test是属性名称,必须加双引号 "{'test': 1}" //test是属性名称,必须用双引号(不能用单引号) "'test'" //test是属性名称,必须用双引号(不能用单引号) ".1" //number 必须以数字开头; "0.1" 将是有效的 "undefined" //undefined 不能表示一个 JSON 字符串; null可以 "NaN" //NaN 不能表示一个 JSON 字符串; 用Infinity直接表示无限也是不允许的
JSON standard does not allow "control characters" such as tabs or line breaks, for example:
// 多数情况下,它会抛出一个错误,因为JS解析器会将字符串中的\t或\n等转义直接视作字面值,起到Tab或换行的效果。 $.parseJSON('{"testing":"1\t2\n3"}')