New JSON method

Source: Internet
Author: User
Tags convert json to string convert string to json string to json

1. Parse (): Convert string to JSON

Parse (): Only parse the JSON form of the string into JS, and the attributes in the string are strictly quoted

Eval (): Can parse any string into JS

var str = ' function show () {alert (123)} ';
eval (str);
Show ();

var str = ' {' name ': ' Hello '} '; Must be in strict JSON form
var json = json.parse (str);
Alert (Json.name)

2. Stringify (): Convert JSON to string

3, the application of the new method

---Deep cloning of new objects

var a ={
Name: {age:100}
}
var str = json.stringify (a);
var b = json.parse (str);
B.name.age = 200;
alert (b.name.age);

New JSON method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.