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