简体   繁体   English

jackson objectMapper.readValue 在空值上失败

[英]jackson objectMapper.readValue fails on empty values

I'm trying to read this json file into a Map { "1": 0, "2": 1, "3": , "4": 5 } my json is very simple but as you see in the example it can have a key with an empty value (null value) on "3".我正在尝试将此 json 文件读入 Map { "1": 0, "2": 1, "3": , "4": 5 } 我的 json 非常简单,但正如您在示例中看到的那样,它可以在“3”上有一个带有空值(空值)的键。 parsing it by:通过以下方式解析:

    Map<String, Object> testMap = objectMapper.readValue(file.getInputStream(), Map.class);

fails with "Unexpected character (',' (code 44)): expected a value"失败并显示“意外字符(','(代码 44)):需要一个值”

is there any way to make this work?有什么办法可以使这项工作?

Thanks谢谢

{ "1": 0, "2": 1, "3": , "4": 5 } is not a valid JSON, so any standard parser would fail. { "1": 0, "2": 1, "3": , "4": 5 }不是有效的 JSON,因此任何标准解析器都会失败。 You can customize a parser or (better) use a regex to substitute the "key": , with "key": null, .您可以自定义解析器或(更好)使用正则表达式将"key": , "key": null,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM