JSON in node. js

Source: Internet
Author: User
VaR STR = '{"dir": "kunhony", "Param": "ARCHIVE"}'; var AAA = JSON. parse (STR); console. log (AAA. param );

The above code is correct, but if you change var STR = '{"dir": "kunhony", "Param": "ARCHIVE"}';: vaR STR = "{'dir': 'kunhony', 'param': 'archive'}"; an error is reported in the code. The specific cause has been hard to understand. I have time to study the node. js source code. Does anyone know? The Code is as follows:

VaR STR = "{'dir': 'kunhony', 'param': 'archive'}"; var AAA = JSON. parse (STR); console. log (AAA. param );
VaR DATA = {dir: 'kunhony', Param: 'archive'}; var STR = JSON. stringify (data); console. log (STR); var AAA = JSON. parse (STR); console. log (AAA. param );

The above code can be used, because JSON. stringify (data); converts the object back to the {"dir": "kunhony", "Param": "ARCHIVE"} string.

 

Note: this problem also exists after testing on the browser. It seems that in JSON, double quotation marks cannot be used for string. Now, let's take a look at this.

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.