Jacson parse JSON string value with backslash error __jacson

Source: Internet
Author: User
Tags control characters

String string= "{\" deviceno\ ": \" C:\\a\ "};

Mybean mybean= (Mybean) jsonmapper.getinstance (). Fromjson (String, Mybean. Class);


The error is as follows:

com.fasterxml.jackson.databind.JsonMappingException:Unrecognized character escape ' a ' (code 77)
At [source:java.io.stringreader@259f1b1d Line:1, column:734] (through reference chain: com.taiji.kafka2stormunite.util.kakouldvehiclepassentity["Imagedescriptions"])
At Com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath (jsonmappingexception.java:232)
At Com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath (jsonmappingexception.java:197)
At Com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow (beandeserializerbase.java:1311)
At Com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject (beandeserializer.java:297)
At Com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize (beandeserializer.java:121)
At Com.fasterxml.jackson.databind.objectmapper._readmapandclose (objectmapper.java:2888)
At Com.fasterxml.jackson.databind.ObjectMapper.readValue (objectmapper.java:2034)
At Com.taiji.kafka2stormunite.util.JsonMapper.fromJson (jsonmapper.java:105)
At Com.taiji.kafka2stormunite.util.JsonMapper.main (jsonmapper.java:221)
caused by:com.fasterxml.jackson.core.JsonParseException:Unrecognized character escape ' M ' (code 77)
At [source:java.io.stringreader@259f1b1d Line:1, column:734]
At Com.fasterxml.jackson.core.jsonparser._constructerror (jsonparser.java:1369)
At Com.fasterxml.jackson.core.base.parserminimalbase._reporterror (parserminimalbase.java:532)
At Com.fasterxml.jackson.core.base.parserminimalbase._handleunrecognizedcharacterescape (ParserMinimalBase.java : 507)
At com.fasterxml.jackson.core.json.readerbasedjsonparser._decodeescaped (readerbasedjsonparser.java:1788)
At Com.fasterxml.jackson.core.json.readerbasedjsonparser._finishstring2 (readerbasedjsonparser.java:1535)
At Com.fasterxml.jackson.core.json.readerbasedjsonparser._finishstring (readerbasedjsonparser.java:1512)
At Com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getText (readerbasedjsonparser.java:205)
At Com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.deserialize ( UNTYPEDOBJECTDESERIALIZER.JAVA:59)
At Com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.mapObject (Untypedobjectdeserializer.java : 211)
At Com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.deserialize ( UNTYPEDOBJECTDESERIALIZER.JAVA:51)
At Com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.mapObject (Untypedobjectdeserializer.java : 225)
At Com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.deserialize ( UNTYPEDOBJECTDESERIALIZER.JAVA:51)
At Com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize (collectiondeserializer.java:230)
At Com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize (collectiondeserializer.java:207)
At Com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize (collectiondeserializer.java:1)
At Com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize (settablebeanproperty.java:464)
At Com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet (methodproperty.java:98)
At Com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject (beandeserializer.java:295)
... 5 more
Interrupted point of view, take value when only take the C:, visible encountered backslash terminated to the character fill to value, the following cannot parse the error.

Com.fasterxml.jackson.core.JsonParser This class sets the JSON parsing property.

/**
* Feature that can is enabled to accept quoting of all character
* Using backslash qooting mechanism:if not enabled, only characters
* that are explicitly listed by JSON specification can is thus
* Escaped (you'll have a JSON spec for small list of characters)
*<p>
* Since JSON specification requires quoting for ' all ' control characters,
* This is a non-standard feature, and as such disabled by default.
*/
Allow_backslash_escaping_any_character (False),
Allow all characters in quotation marks to be accepted, false by default

Set to True to solve the problem.

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.