日期:2014-05-16  浏览次数:20677 次

JSON问题 - Web 开发 / Ajax
List<JiaMiGoodsCat> goodsCat = jiaMiGoodsCatService.selectJiaMiGoodsCat(shop.getShopId());
JSONArray jsonArray = JSONArray.fromObject(goodsCat);  

response.setContentType("text/html;charset=utf-8");  
PrintWriter out = response.getWriter(); 
out.println(jsonArray); 


返回的JSON对象

[{"count":0,"goods_id":"","id":"2c9081f227efb3670127eff744e10021","name":"3434","pwd":"b57f370ea0325d22e3512620fb9fbf02","shopId":"2c9081f227a7836c0127a7858e9e0003"},{"count":0,"goods_id":"","id":"2c9081f227efb3670127eff88b0e0022","name":"二二","pwd":"363aa3bed5a7567754d78dd4fb4cdf00","shopId":"2c9081f227a7836c0127a7858e9e0003"},{"count":0,"goods_id":"","id":"2c9081f227efb3670127eff5b9df001e","name":"asdfsdafa","pwd":"363aa3bed5a7567754d78dd4fb4cdf00","shopId":"2c9081f227a7836c0127a7858e9e0003"},{"count":0,"goods_id":"","id":"2c9081f227efb3670127f0099dd60024","name":"撒旦法撒旦法","pwd":"b57f370ea0325d22e3512620fb9fbf02","shopId":"2c9081f227a7836c0127a7858e9e0003"},{"count":0,"goods_id":"","id":"2c9081f227efb3670127effdbe190023","name":"撒旦法撒旦法","pwd":"b57f370ea0325d22e3512620fb9fbf02","shopId":"2c9081f227a7836c0127a7858e9e0003"}]

正确的格式 

[{count:0,goods_id:"",id:"2c9081f227efb3670127eff744e10021",name:"3434",pwd:"b57f370ea0325d22e3512620fb9fbf02",shopId:"2c9081f227a7836c0127a7858e9e0003"}]

怎么多了引号






------解决方案--------------------
var 0={
"key":'value'
}
这样写是正确的
------解决方案--------------------
给 name 设置 "" 是正确的

这样才能使用 eval 将 json 字符串 转换为 json 对象
------解决方案--------------------
没有那个引号就不对啦!