我在json下面从第三方API检索。
{ 'id': 1, 'name': "user1", 'address': "IN", }
我如何用杰克逊映射器解析这个问题。我得到以下异常:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
我的代码如下:
objectMapper = new ObjectMapper();
objectMapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
objectMapper.configure(JsonParser.Feature.ALLOW_MISSING_VALUES, true);
objectMapper.readTree("{ 'id': 1, 'name': \"user1\", 'address': \"IN\", }");
注意:我不想替换最后一个逗号,我想知道是否有任何选项让杰克逊能够解释它?
答案 0 :(得分:3)
根据https://github.com/FasterXML/jackson-core/issues/118 只需添加:
JsonParser.ALLOW_TRAILING_COMMA
查看更多信息: https://github.com/FasterXML/jackson-core/issues/323