How JSON strings are represented in JavaScript and Java code

Source: Internet
Author: User

When I recently used JS to write a JSON-style string, when I put the JSON form string into the function json.parse (), always error uncaught syntaxerror:unexpected token '

javascript: Among

The string is:

var StrJso2 = "{' UserID ': ' One ', ' Name ': ' WP ', ' email ': ' [email protected] '}";

It looks right, but it's actually a background error.

The correct format is:

var strjso2= ' {"UserID": "One", "Name": "WP", "email": "[email protected]"} ';

Pure JS string preferably using double quotation marks

Java code

So write String strjson= ' {"UserID": One, "Name": {"FirstName": "tht", "LastName": "Tang"}, "email": "[email protected]"} '; Must be wrong, because the single quote is the char type

Correct format:

String strjson= "{' UserID ': One, ' Name ': {' FirstName ': ' tht ', ' LastName ': ' Tang '}, ' email ': ' [email protected] '}";

Or

String strjson= "{\" userid\ ": \" 11\ ", \" name\ ": {\" firstname\ ": \" tht\ ", \" lastname\ ": \" tang\ "}, \" email\ ": \" [Email Protected]\ "}";

How JSON strings are represented in JavaScript and Java code

Related Article

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.