下面是从第三方API检索的JSON。
{ 'id': 1, 'name': "user1", 'address': "IN", }
我如何用Jacksonmapper解析这个。我得到下面的异常:
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\", }");
注意:我不想替换最后一个逗号,我想知道是否有任何选项可以让Jackson排除那个逗号?
2条答案
按热度按时间zbdgwd5y1#
根据https://github.com/FasterXML/jackson-core/issues/118只需添加:
查看更多信息:https://github.com/FasterXML/jackson-core/issues/323
u91tlkcl2#
在Jackson+中,它的配置略有不同: