用来举例的json串:
这里的json串就是我下面代码里的 imgpathoflist
[
{"tag":"temp@AF175C29B75F72B9",
"tagName":"1111",
"position":{
"x":"40.657%",
"y":"8.854%",
"x1":"63.295%",
"y1":"28.332%"
},
"uuid":"E13FAC5F8AB0AD88"
},
{"tag":"temp@C4828D78CED8B87C",
"tagName":"2222",
"position":{
"x":"15.059%",
"y":"37.839%",
"x1":"80.18599999999999%",
"y1":"60.099999999999994%"
},
"uuid":"D42D84A8A6B88931"
},
{"tag":"temp@79ED4137F1AE4158",
"tagName":"3333",
"position":{
"x":"13.343%",
"y":"67.458%",
"x1":"87.919%",
"y1":"92.2%"
},
"uuid":"79ED4137F1AE4158"
}
]
转换成List<Map<String,Object>>类型的格式
ObjectMapper mapper = new ObjectMapper();
MapLikeType mapLikeType = mapper.getTypeFactory().constructMapLikeType(Map.class, Object.class, Object.class);
CollectionType collectionType = mapper.getTypeFactory().constructCollectionType(List.class, mapLikeType);
try {
List<Map<String, Object>> o = mapper.readValue(imgpathoflist, collectionType);
tInformationAccess.setImgPathOfList(o);
} catch (IOException e) {
e.printStackTrace();
}
已经ok了,看图
接下来,我们在把这个List<Map<String, Object>> o 转换成json串, 这样可以直接存到数据库里,想用这条数据的时候,就查出来,用长面的方法再把这个json串解析成自己想要的结构的类
String json = JSON.toJSONString(imgPathOfList);