与xml相比,json小巧但描述能力却不差。其实json就是一串字符串,对于前台传入的json数组,是可以转为list的。本文介绍json数组转化为list的两种方法。
1、依赖ObjectMapper类(使用简洁)
publicvoidtestConvert(){
finalObjectMappermapper=newObjectMapper();
jsonString=[{"id":"123","name":"李四",},{"id":"6666","name":"李五",}];
List<DtoBean>listll=mapper.readValue(jsonString,newTypeReference<List<DtoBean>>(){});
}
2、利用JSONArray中的parse方法来解析json数组字符串
List<Map<String,String>>listObjectFir=(List<Map<String,String>>)JSONArray.parse(strArr);
System.out.println;
for(Map<String,String>mapList:listObjectFir){
for(Map.Entryentry:mapList.entrySet()){
System.out.println(entry.getKey()+""+entry.getValue());
}
}
原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容