js 怎么去除数组子对象的双引号?

问题描述

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进行修改,这是最理想的

时间: 2024-09-26 11:21:55

js 怎么去除数组子对象的双引号?的相关文章

JS简单去除数组中重复项的方法_javascript技巧

本文实例讲述了JS简单去除数组中重复项的方法.分享给大家供大家参考,具体如下: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var arr = ["aaa","bb

js 高效去除数组重复元素示例代码

 有关使用js去除数组重复元素的文章在之前也有介绍过,下面有个不错示例,感兴趣的朋友可以参考下 代码如下: function unique(data){  data = data || [];  var a = {};  for (var i=0; i<data.length; i++) {  var v = data[i];  if (typeof(a[v]) == 'undefined'){  a[v] = 1;  }  };  data.length=0;  for (var i in a

浅析Js中的单引号与双引号问题_javascript技巧

单引号和双引号其实没啥区别,看你自己习惯了 <input type="button" onclick="alert("1")">-------------------不正确<input type="button" onclick="alert('1')">-------------------正确 双引号中再用双引号要这样:var str = "abc\"def\

js 巧妙去除数组中的重复项_javascript技巧

时不时的看下YUI的源码, 总会有些收获. 一. YUI中的源码' 复制代码 代码如下: var toObject = function(a) { var o = {}; for (var i=0, j=a.length; i<j; i=i+1) { // 这里我调整了下, YUI源码中是i<a.length o[a[i]] = true; } return o; }; var keys = function(o) { var a=[], i; for (i in o) { if (o.has

js 高效去除数组重复元素示例代码_javascript技巧

复制代码 代码如下: function unique(data){ data = data || []; var a = {}; for (var i=0; i<data.length; i++) { var v = data[i]; if (typeof(a[v]) == 'undefined'){ a[v] = 1; } }; data.length=0; for (var i in a){ data[data.length] = i; } return data; } function t

Js参数值中含有单引号或双引号问题的解决方法_javascript技巧

<script type="text/javascript">function Display(LoginEmail, UserName, ID) {        alert(LoginEmail);    }</script> 1.使用单引号传参:<a href="javascript:Display('abc@abc.com','Aleax Xie','10101239393')">Test1</a> 如果其中一

javascript-js 怎样去除数组重复项

问题描述 js 怎样去除数组重复项 var arr=[ {a:3,b:4,c:5}, {a:4,b:5,c:6}, {a:3,b:4,c:5}, {a:2,b:4,c:5} ] 将数组的重复项去掉: var arr=[ {a:3,b:4,c:5}, {a:4,b:5,c:6}, {a:2,b:4,c:5} ] 解决方案 <script> function equals( x, y ) { for ( var p in x ) { if ( x.hasOwnProperty( p ) ) { i

js中单引号与双引号冲突

 如何解决js中单引与双引冲突,想下面的这段代码: 代码如下 html += ' <a onclick="return removeOpenCss('+e.point.lng+e.point.lat+')">取消</a>';   这是js中的代码,如果这里这样写的话,会提示js错误,是因为removeOpenCss方法里的参数没有单引或者双引,如果这里,这样写的话: 代码如下 html += ' <a onclick="return remove

js 赋值包含单引号双引号问题的解决方法

 这篇文章主要介绍了js赋值包含单引号双引号问题的解决方法,需要的朋友可以参考下 我的页面是jsp页面,里面包含一个参数:lefttree,    这个lefttree是从后台拼出来的,内容是html代码:如:  代码如下: <div class="test" onclick="show('tt1','abc')">    在jsp页面中,需要通过js代码将这个值付给一个div,如下:  代码如下: <script type="text/