SpringMvc项目 FastJson的数据中有$ref解决办法
这是FastJson返回的数据,经过在线json格式转换工具转换的数据
阴影部分套用上面的dept(部门)信息,使用easyui只能获取第一行,凡是引用的都无法获取
经各种搜索: 推荐网址:http://www.07net01.com/2015/10/941178.html
给出自己的解决方案(有大神说可能会破坏数据) ---本人目前在公司实习,技术还不行,咳咳
这是在网上搜的js文件,具体出处http://code.taobao.org/p/fastjson-js/src/FastJson-1.0.min.js
项目中加入JS并导入(具体看自己的所放JS文件路径):
<script src="${base}/static/bootstrap-3.3.5/js/FastJson-1.0.min.js" type="text/javascript"></script>
另在加载时添加loadFilter方法
loadFilter: function(data){ FastJson.format(data);//重点!! for(var i = 0;i<data.rows.length;i++){ data.rows[i].dept = data.rows[i].dept.name; } return data; }
<th data-options="field:'dept',width:150,sortable:true">所属部门</th>
此列会显示!
第二种解决方式:
通过配置文件改变返回数据格式--不进行引用
1 <!-- spring解析返回结果成json --> 2 <mvc:message-converters register-defaults="true"> 3 <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> 4 <property name="supportedMediaTypes"> 5 <list> 6 <value>text/html;charset=UTF-8</value> 7 <value>application/json</value> 8 </list> 9 </property> 10 <property name="features"> 11 <list> 12 <value>PrettyFormat</value> 13 <value>WriteMapNullValue</value> 14 <value>WriteNullStringAsEmpty</value> 15 <value>WriteNullListAsEmpty</value> 16 <value>DisableCircularReferenceDetect</value> 17 </list> 18 </property> 19 </bean> 20 </mvc:message-converters>