Java Jackson 错误意外字符 ('}' (代码 125))
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19709897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hymanson Error Unexpected character ('}' (code 125))
提问by Rollyng
Hey i got an issue based on deserialization with Hymanson, here what i've tried and the error i got.
嘿,我遇到了一个基于 Hymanson 反序列化的问题,这里是我尝试过的和我遇到的错误。
ERROR: com.fasterxml.Hymanson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
错误:com.fasterxml.Hymanson.core.JsonParseException:意外字符('}'(代码 125)):期待双引号开始字段名称
Java Code
Java代码
List<Contact> ds = mapper.readValue(data, mapper.getTypeFactory().constructCollectionType(List.class, Contact.class));
//OR this one
List<Contact> ds = mapper.readValue(data, new TypeReference<List<Contact>>() {});
My JSON
我的 JSON
[
{
"id": "200",
"name": "Alexia Milano",
"email": "[email protected]",
"prenom": "xx-xx-xxxx,x - street, x - country",
}, {
"id": "201",
"name": "Johnny Depp",
"email": "[email protected]",
"prenom": "xx-xx-xxxx,x - street, x - country",
}
]
采纳答案by eis
If you use json validator, you can see more detailed error message:
如果您使用json validator,您可以看到更详细的错误消息:
Parse error on line 6:
...ntry", }, { "id
---------------------^
Expecting 'STRING'
you have extra comma there after "xx-xx-xxxx,x - street, x - country"
. If you remove it from both two places, you have valid JSON and Hymanson parsing works.
之后有额外的逗号"xx-xx-xxxx,x - street, x - country"
。如果您从两个地方都将其删除,则您具有有效的 JSON 和 Hymanson 解析工作。
回答by Martin Seeler
It's because your last entries, there is an ,
after your last value. Thats why Hymanson expects another field.
这是因为您的最后一个条目,,
在您的最后一个值之后。这就是Hyman逊期待另一个领域的原因。