NutzCN Logo
问答 map类型的字符串转成map类型出错
发布于 2055天前 作者 MrSongPing 2736 次浏览 复制 上一个帖子 下一个帖子
标签:

数据:

{
	linkList=[{name=, id=d1ade9ce7c94466db617a35bc350d295, source=1d9cfb4d5b164ee18f78a386093b7d6b, category=2, target=fdc2cd75c27c486390dc69576632bd57}],
	nodeList=[
		{draggable=true, data=null, moved=false, name=酒泉, x=48, y=200, weight=0, monitor=null, id=1d9cfb4d5b164ee18f78a386093b7d6b, category=0, type=2, value=null}, 
		{draggable=true, data=null, moved=false, name=宁夏, x=172, y=23, weight=0, monitor=null, id=bf38a6c3facb44a7a81670cdd6716a64, category=0, type=2, value=null}, 
		{draggable=true, data=null, moved=false, name=兰州, x=100, y=122, weight=0, monitor=null, id=fdc2cd75c27c486390dc69576632bd57, category=0, type=2, value=null}
	], 
	dictList=[
		{classify=告警级别, code=3, name=警告, remark=#3333fe, id=042ff8df57bf4e7b863618a40b8a24a8, sort=3, delFlag=false}, 
		{classify=告警级别, code=4, name=错误, remark=#f3fb10, id=d35c81fbeaa144be87602d1c2a7dc67b, sort=4, delFlag=false}, 
		{classify=告警级别, code=5, name=致命, remark=#fd2020, id=31b62b41cea54cdcb0c4ec398fec9100, sort=5, delFlag=false}
	]
}

操作代码如下:

		File file=tempFile.getFile();
		String fileDate=fileDataService.readerFile(file);
		if("".equals(fileDate)){
			return new Result(false,"该文件没有数据!");
		}
		NutMap map=Json.fromJson(NutMap.class,Json.toJson(fileDate));

出现错误:

org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <org.nutz.lang.util.NutMap> for {{linkList=[{name=, id=d1ade9ce7c94466db617a35bc350d295, source=1d9cfb4d5b164ee18f78a386093b7d6b, category=2, target=fdc2cd75c27c486390dc69576632bd57}], nodeList=[{draggable=true, data=null, moved=false, name=酒泉, x=48, y=200, weight=0, monitor=null, id=1d9cfb4d5b164ee18f78a386093b7d6b, category=0, type=2, value=null}, {draggable=true, data=null, moved=false, name=宁夏, x=172, y=23, weight=0, monitor=null, id=bf38a6c3facb44a7a81670cdd6716a64, category=0, type=2, value=null}, {draggable=true, data=null, moved=false, name=兰州, x=100, y=122, weight=0, monitor=null, id=fdc2cd75c27c486390dc69576632bd57, category=0, type=2, value=null}], dictList=[{classify=告警级别, code=3, name=警告, remark=#3333fe, id=042ff8df57bf4e7b863618a40b8a24a8, sort=3, delFlag=false}, {classify=告警级别, code=4, name=错误, remark=#f3fb10, id=d35c81fbeaa144be87602d1c2a7dc67b, sort=4, delFlag=false}, {classify=告警级别, code=5, name=致命, remark=#fd2020, id=31b62b41cea54cdcb0c4ec398fec9100, sort=5, delFlag=false}]}}

7 回复

这不是合法json,无法处理

从源头解决呗,这种数据就不是json

@wendal 但是这种格式是map格式,怎样才能将map类型的字符串转换成map类型呢?

转不回来的

@wendal 从源头上来说,那这种map类型怎么转换为标准的json格式呢?Json.toJson(map)的格式好像没用

怎么就没用了?Json.toJson输出的就是json字符串呀

添加回复
请先登陆
回到顶部