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
Release: 2016-05-16 16:41:10
Original
1389 people have browsed it

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" );
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template