我正在尝试解析 datas.json 中存在的 JSON 数据。我需要使用 Beans/POJO 类解析排除数据。JSON 数据如下:
"ExclusionList" : {
"serviceLevel" : ["sl1","sl2","sl3"],
"item" : ["ABC","XYZ"] } }
我为 ExclusionList 创建了 POJO 类,但无法在 ECLIPSE IDE.Mypojo 类的控制台中获取和打印:
List<String> serviceLevel;
List<String> item;
//with gettter and setters.
我的主要课程如下:
public static void main(String[] args)
throws JsonParseException, JsonMappingException, IOException, ParseException, JSONException {
File jsonFile = new File("C:\\Users\\sameepra\\Videos\\datas.json");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
ExclusionList exclusionlist=mapper.readValue(jsonFile,ExclusionList.class);
List<String> excllist=exclusionlist.getServiceLevel();
for (int i = 0; i < excllist.size(); i++) {
System.out.println(excllist.get(i));
}
}
在线程“main”java.lang.NullPointerException中获取错误作为异常
慕哥6287543
忽然笑
随时随地看视频慕课网APP
相关分类