NutzCN Logo
问答 JSON 转换 &quot 怎么处理呢
发布于 1958天前 作者 Hamming 29442 次浏览 复制 上一个帖子 下一个帖子
标签:
ServiceFees serviceFees = serviceFeesService.fetch(id);
		serviceFeesService.fetchLinks(serviceFees,"serviceFeeItemList");
		req.setAttribute("serviceFees",serviceFees);
		String source ="[]";
		if(Lang.isNotEmpty(serviceFees) && Lang.isNotEmpty(serviceFees.getServiceFeeItemList())){
//			source =  Json.toJson(serviceFees.getServiceFeeItemList());
			source =  JSON.toJSONString(serviceFees.getServiceFeeItemList());
		}
		req.setAttribute("source",  source);

source = Json.toJson(serviceFees.getServiceFeeItemList());
页面报错了;
source = JSON.toJSONString(serviceFees.getServiceFeeItemList());
还能输出日志
JSON 转换 &quot 怎么处理呢 求指点

[{"createBy":"1","createTime":1565602210000,"id":"3bd113782950422ca80e79fef0413b59","name":"半年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":6},{"createBy":"1","createTime":1565602210000,"id":"87bafc6b0a554af89320ae95fc1ef6ad","name":"季付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":3},{"createBy":"1","createTime":1565602211000,"id":"883433f0eda54aaf8fe3c9fe0e0141b8","name":"2年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602211000,"value":24},{"createBy":"1","createTime":1565602210000,"id":"d84c61fd82d2407e98d47a9412d0ca64","name":"月付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":1},{"createBy":"1","createTime":1565602210000,"id":"dec30ab98399431987f66e04637c18cc","name":"年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":12}]
6 回复

c:out,加上escapeXml="false"

断点json 得到的值是

[{"createBy":"1","createTime":1565602210000,"id":"3bd113782950422ca80e79fef0413b59","name":"半年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":6},{"createBy":"1","createTime":1565602210000,"id":"87bafc6b0a554af89320ae95fc1ef6ad","name":"季付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":3},{"createBy":"1","createTime":1565602211000,"id":"883433f0eda54aaf8fe3c9fe0e0141b8","name":"2年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602211000,"value":24},{"createBy":"1","createTime":1565602210000,"id":"d84c61fd82d2407e98d47a9412d0ca64","name":"月付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":1},{"createBy":"1","createTime":1565602210000,"id":"dec30ab98399431987f66e04637c18cc","name":"年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":12}]

thymeleaf 页面取值是

 var source = "[[${source}]]";
    console.log(source);
[{"createBy":"1","createTime":1565602210000,"id":"3bd113782950422ca80e79fef0413b59","name":"半年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":6},{"createBy":"1","createTime":1565602210000,"id":"87bafc6b0a554af89320ae95fc1ef6ad","name":"季付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":3},{"createBy":"1","createTime":1565602211000,"id":"883433f0eda54aaf8fe3c9fe0e0141b8","name":"2年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602211000,"value":24},{"createBy":"1","createTime":1565602210000,"id":"d84c61fd82d2407e98d47a9412d0ca64","name":"月付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":1},{"createBy":"1","createTime":1565602210000,"id":"dec30ab98399431987f66e04637c18cc","name":"年付","rate":1.0,"serviceFeesId":"7278ffb0d1ab4f5f997616d6d90709c8","updateBy":"1","updateTime":1565602210000,"value":12}]

这个是什么原因呢

@qq_4f9057d2 感谢回复 但是 是用的thymeleaf

查thymeleaf的文档嘛,不转义输出

感谢 兽总 已经解决

<script th:inline="javascript">
    //页面显示异常 不转义输出
    //<![CDATA[
    var source = [[${source}]];
    console.log(source);
    source = JSON.parse(source);
    console.log(source);
    //]]>

</script>
添加回复
请先登陆
回到顶部