问题描述
Ext.Ajax.request({url : ctxpath + '/ShopManager/LoadPlanListGrid',params : {},method : 'post',callback : function(options, success, response) {var json = Ext.JSON.decode(response.responseText);var store = Ext.create('Ext.data.Store', {fields : json.fields,data : json.datas});Ext.getCmp("configGrid").reconfigure(store, json.columns);}}); 以上代码,当json.datas的格式是这样的:["{"key1":"value1"}","{"key2":"value2"}"] 请问下怎么将数据改为:[{"key1":"value1"},{"key2":"value2"}]这种格式,不然取不到key1,key2及其对应的值。 问题补充:{ "columns":[ {"align":"center","dataIndex":"goods_name","sortable":true,"text":"商品名称","width":200}, {"align":"center","dataIndex":"goods_type","sortable":true,"text":"存货类别","width":200}, {"align":"center","dataIndex":"goods_supply_factory","sortable":true,"text":"供应商","width":200}, {"align":"center","dataIndex":"goods_factory","sortable":true,"text":"生产厂家","width":200}, {"align":"center","dataIndex":"goods_spec","sortable":true,"text":"规格","width":200}, {"align":"center","dataIndex":"goods_unit","sortable":true,"text":"计量单位","width":200}, {"align":"center","dataIndex":"goods_price_first","sortable":true,"text":"采购价格","width":200}, {"align":"center","dataIndex":"goods_price_last","sortable":true,"text":"结算价格","width":200}, {"align":"center","dataIndex":"goods_price_first_all","sortable":true,"text":"计划采购金额","width":200}, {"align":"center","dataIndex":"stock_plan_first_all","sortable":true,"text":"计划合计","width":200}, {"align":"center","dataIndex":"goods_price_last_all","sortable":true,"text":"实际采购金额","width":200}, {"align":"center","dataIndex":"stock_plan_last_all","sortable":true,"text":"实际合计","width":200}, {"columns":[ {"align":"center","dataIndex":"hn_jinchuan#stock_plan_first","sortable":true,"text":"计划","width":100}, {"align":"center","dataIndex":"hn_jinchuan#stock_plan_last","sortable":true,"text":"实际","width":100}, {"align":"center","dataIndex":"hn_jinchuan#goods_price_last_all","sortable":true,"text":"金额","width":100}],"text":"金川猪场"} ], "condition":null, "datas":"[ {"goods_unit":"包", "stock_plan_last_all":"115.0", "hn_jinchuan#stock_plan_first":"115", "goods_factory":"勃林格殷格翰美国子公司(密苏里州)", "goods_price_first_all":"149500.0", "goods_price_last":"1300.00", "goods_name":"民星六甲氧散1kg×10包", "goods_supply_factory":"", "goods_price_last_all":"149500.0", "stock_plan_first_all":"115.0", "goods_price_first":"1300.00", "hn_jinchuan#stock_plan_last":"115", "goods_type":"粉散剂", "goods_spec":"1kg×10包", "hn_jinchuan#goods_price_last_all":"149500.0"}]", "fields":[ {"mapping":"goods_name","name":"goods_name","type":"String"}, {"mapping":"goods_type","name":"goods_type","type":"String"}, {"mapping":"goods_supply_factory","name":"goods_supply_factory","type":"String"}, {"mapping":"goods_factory","name":"goods_factory","type":"String"}, {"mapping":"goods_spec","name":"goods_spec","type":"String"}, {"mapping":"goods_unit","name":"goods_unit","type":"String"}, {"mapping":"goods_price_first","name":"goods_price_first","type":"String"}, {"mapping":"goods_price_last","name":"goods_price_last","type":"String"}, {"mapping":"goods_price_first_all","name":"goods_price_first_all","type":"String"}, {"mapping":"stock_plan_first_all","name":"stock_plan_first_all","type":"String"}, {"mapping":"goods_price_last_all","name":"goods_price_last_all","type":"String"}, {"mapping":"stock_plan_last_all","name":"stock_plan_last_all","type":"String"}, {"mapping":"hn_jinchuan#stock_plan_first","name":"hn_jinchuan#stock_plan_first","type":"String"}, {"mapping":"hn_jinchuan#stock_plan_last","name":"hn_jinchuan#stock_plan_last","type":"String"}, {"mapping":"hn_jinchuan#goods_price_last_all","name":"hn_jinchuan#goods_price_last_all","type":"String"} ], "submitTime":"2013-08" }
解决方案
重新转换,参考一下:http://zyn010101.iteye.com/blog/955989
解决方案二:
你的后台转换list为json格式的函数错误导致的,鉴定完毕
解决方案三:
{ "datas":[ {"goods_unit":"包", "stock_plan_last_all":"115.0", "hn_jinchuan#stock_plan_first":"115", "goods_factory":"勃林格殷格翰美国子公司(密苏里州)", "goods_price_first_all":"149500.0", "goods_price_last":"1300.00", "goods_name":"民星六甲氧散1kg×10包", "goods_supply_factory":"", "goods_price_last_all":"149500.0", "stock_plan_first_all":"115.0", "goods_price_first":"1300.00", "hn_jinchuan#stock_plan_last":"115", "goods_type":"粉散剂", "goods_spec":"1kg×10包", "hn_jinchuan#goods_price_last_all":"149500.0"}]}}还回的形式像这样就可以了[]数组不要加引号,另外外面需要{}测试 console.info(json.datas[0].goods_unit)这个时候就会去到 "包"
解决方案四:
你的后台代码写的不太好,应该返回一个List集合之类的数据,然后将集合类型变为json字符串输出
解决方案五:
是你的json格式出现问题,json 文本类型为 :var jsonTxt = '[{"key1":"value1"},{"key2":"value2"}]';json对象为 [{"key1":"value1"},{"key2":"value2"}]所以你的json 什么多不是,你最好是在后台还回的组装json进行修改,这是最理想的