关于json数据转map的问题 was expecting comma to separate OBJECT entries
json数据转化出错.
-------------------出错的代码--------------------------------
ObjectMapper objectMapper = new ObjectMapper();
//String ss = "{\"where\":\" if (\\\"\'浙江省\'\\\" = \\\"\'\'\\\", 1=0, cus.state in (\'浙江省\')) or if (\\\"\'\'\\\"=\\\"\'\'\\\", 1=0, cus.city in (\'\')) or if (\\\"\'\'\\\"=\\\"\'\'\\\", 1=0, cus.district in (\'\')) \"}";
String ss = "{\"where\":\" if (\"'浙江省'\" = \"''\", 1=0, cus.state in ('浙江省')) or if (\"''\"=\"''\", 1=0, cus.city in ('')) or if (\"''\"=\"''\", 1=0, cus.district in ('')) \"}";
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES , true);
Map<String,Object> sql_map = objectMapper.readValue(ss,HashMap.class);
System.out.println(sql_map.get("where"));
Exception in thread "main" org.codehaus.jackson.JsonParseException: Unexpected character (''' (code 39)): was expecting comma to separate OBJECT entries
at [Source: java.io.StringReader@b76fa; line: 1, column: 18]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:400)
at org.codehaus.jackson.map.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:304)
at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:249)
at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:33)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2723)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1854)
at com.hupun.crm.business.custom.impl.TestJson.main(TestJson.java:53)
-------------------------------修改后----------------------
ObjectMapper objectMapper = new ObjectMapper();
String ss = "{\"where\":\" if (\\\"\'浙江省\'\\\" = \\\"\'\'\\\", 1=0, cus.state in (\'浙江省\')) or if (\\\"\'\'\\\"=\\\"\'\'\\\", 1=0, cus.city in (\'\')) or if (\\\"\'\'\\\"=\\\"\'\'\\\", 1=0, cus.district in (\'\')) \"}";
//String ss = "{\"where\":\" if (\"'浙江省'\" = \"''\", 1=0, cus.state in ('浙江省')) or if (\"''\"=\"''\", 1=0, cus.city in ('')) or if (\"''\"=\"''\", 1=0, cus.district in ('')) \"}";
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES , true);
Map<String,Object> sql_map = objectMapper.readValue(ss,HashMap.class);
System.out.println(sql_map.get("where"));