Home >Web Front-end >JS Tutorial >jQuery.parseJSON(json) converts JSON string into js object_jquery

jQuery.parseJSON(json) converts JSON string into js object_jquery

WBOY
WBOYOriginal
2016-05-16 16:41:101368browse

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" );
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn