把json字符串转换成复杂的类型格式

用来举例的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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值