JSON string converted to JSON object

Source: Internet
Author: User
A parse method for a JSON object

ie8+, Chrome, Safari, and Firefox browsers are all supported.

var str = ' {' name ': ' Zhang San '} '; var obj = json.parse (str);

The disadvantage is that if the string is not in the standard format (for example, the key name is not quoted), the Uncaught SyntaxError exception is thrown.

Two eval functions

eval()The function executes the incoming string as a JavaScript code. The JSON string may not be in the standard format.

But eval can execute any string passed in, which poses a security issue. At the same time, the eval and with will change the lexical scope of JS, and affect the optimization of the browser engine's word-domain scope, thus affecting the performance.

var obj = eval (' {name: ' Zhang San '} ');
Three function functions

JSON string converted to JSON object

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.