Java supports JSON single quote parsing

Source: Internet
Author: User

I am trying to does this [see below], and it is throwing error.

String x= "{' Candidateid ': ' K ', ' Candeducationid ': 1, ' activitiessocieties ': ' Activities for Cand1 '}"; objectmapper Mapper = new Objectmapper (); try {    jsonnode df=mapper.readvalue (x,jsonnode.class);    int i=0;} Catch.....

Exception:

org.codehaus.jackson.JsonParseException:Unexpected character ("code"): is expecting Double-quote to Start field N ameat [Source: [email protected]; line:1, Column:3] at  org.codehaus.jackson.jsonparser._constructerror ( jsonparser.java:1291)

Solution:

It's not a valid JSON, but I can tell Jackson to allow it. Here's how.

String x = "{' Candidateid ': ' K ', ' Candeducationid ': 1, ' activitiessocieties ': ' Activities for Cand1 '}"; objectmapper Mapper = new Objectmapper (); Mapper.configure (JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); Jsonnode df = mapper.readvalue (x, Jsonnode.class); System.out.println (Df.tostring ());//output: {"Candidateid": "K", "Candeducationid": 1, "activitiessocieties": " Activities for Cand1 "}

  

Java supports JSON single quote parsing

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.