A question about double quotation marks in Java JSON parsing, javajson

Source: Internet
Author: User

A question about double quotation marks in Java JSON parsing, javajson

Parse a json data:

{"Manifest": {Version: "3.0 "}}

If you look at it carefully, this string is not in the regular json format. if the Version is missing double quotation marks, it should be:

{"Manifest": {"Version": "3.0 "}}

 

If you use

JSONObject mainfestObject. getJSONObject ("manifest ");

This method will cause an error, but if you use

String mainfestStr = object. optString ("manifest ","");


JSONObject mainfestObject = new JSONObject (mainfestStr );

The above method is successfully parsed!


Java: What should I do if I want to parse JSON but encounter many double quotation marks?

Json parsing has many ready-made

Json-lib

Gson

Do you want to build your own tires?

The regular expression is used to parse JSON objects, and double quotation marks are processed.

Not much nonsense
Directly Add code
Json does not
Js Code
A = '"Vietnam bans Chinese stamps and indicates that the printed Xisha Islands are" Vietnamese territory ""'; var B; B =. replace (/"Vietnamese territory"/, '\ "Vietnamese territory \"'); document. write (B );

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.