我有一个JSON文件,看起来像这样:
{
"caseNumber": "kblndw896",
"features": [
{
"id1": "wad12jkb",
"id2": "jBgioj",
"id3": "jabd8&",
"limit": "500000",
"M1": "333487.2",
"M2": "339259.88",
"M3": "316003.84",
"M4": "219097.12",
"M5": "393842.98",
"M6": "498684.1",
"M7": "1074002.44",
"M8": "437211.19",
"M9": "444842.35",
"M10": "657756.22",
"M11": "571928.78",
"M12": "230378.06"
}
]
}
现在我尝试导入这个文件,并放入名为Payload的POJO类,它具有POJO类的子特性。现在,当我使用ObjectMapper
导入时:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
Payload payload= mapper.readValue(new File("filepath\\file.json"),
Payload.class);
然后我把它导入到payload POJO类中,但是features数组中的键的值对于所有键都是null值。
例如,导入的数据为:
{
"caseNumber": "kblndw896",
"features": [
{
"id1": null,
"id2": "null",
"id3": "null",
"limit": null,
"m7": null,
"m6": null,
"m9": null,
"m4": null,
"m11": null,
"m8": null,
"m2": null,
"m12": null,
"m1": null,
"m3": null,
"m5": null,
"m10": null
}
]
}
如何从文件中获取值?
尝试:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
Payload payload= mapper.readValue(new File("filepath\\file.json"),
Payload.class);
预期:
{
"caseNumber": "kblndw896",
"features": [
{
"id1": "wad12jkb",
"id2": "jBgioj",
"id3": "jabd8&",
"limit": "500000",
"M1": "333487.2",
"M2": "339259.88",
"M3": "316003.84",
"M4": "219097.12",
"M5": "393842.98",
"M6": "498684.1",
"M7": "1074002.44",
"M8": "437211.19",
"M9": "444842.35",
"M10": "657756.22",
"M11": "571928.78",
"M12": "230378.06"
}
]
}
1条答案
按热度按时间wlzqhblo1#
我会这样做:
这是
class Features
这是
class Payload
最后: