一只努力学习的弱鸡 2017-09-15 07:08 采纳率: 71.4%
浏览 1781
已采纳

Js循环json数组 求大佬帮助

{
"obj": "{\"cust_info\":[{\"CUST_NAME_FULL\":\"李莉\"}],\"cycle\":[\"0\"],\"error\":\"0\",\"countByHour_mx\":\t[{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"16\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170821102550\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"72\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170821150525\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"87\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822104713\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"20\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822105901\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"75\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822133935\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},,{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"45\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170823175811\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"163\",\"YSJE\":\"0.30\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170820153942\",\"JFJE\":\"0.30\",\"BJHM\":\"13q009907707\",\"JFCS\":\"3\",\"YHJE\":\"0.00\"}],\"error_message\":\"\",\"countByHour_hj\":[{\"SYLX\":\"48\",\"THSC\":\"3719\",\"YSJE\":\"9.10\",\"HDZS\":\"48\",\"JFJE\":\"9.10\",\"JFCS\":\"91\",\"YHJE\":\"0.00\"}]}"
}

这个是Json 我想把这个数组循环出来

  • 写回答

5条回答 默认 最新

  • 斯洛文尼亚旅游 2017-09-15 08:30
    关注

    你的这个字符格式有问题。。

    这里有2个逗号,没有办法转成json的,是你打错了还是返回的就是这样,返回就这样需要自己去掉。如果格式错很多只能正则了
     .\":\"0.00\"},,{\"SYLX\":\
    
    
        //如果你贴出来的那串是字符串,那么下面这句改为var o=JSON.parse(存储字符串的变量名);
        var o = { "obj": "{\"cust_info\":[{\"CUST_NAME_FULL\":\"李莉\"}],\"cycle\":[\"0\"],\"error\":\"0\",\"countByHour_mx\":\t[{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"16\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170821102550\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"72\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170821150525\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"87\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822104713\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"20\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822105901\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"75\",\"YSJE\":\"0.20\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170822133935\",\"JFJE\":\"0.20\",\"BJHM\":\"13009907707\",\"JFCS\":\"2\",\"YHJE\":\"0.00\"},,{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"45\",\"YSJE\":\"0.10\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170823175811\",\"JFJE\":\"0.10\",\"BJHM\":\"13009907707\",\"JFCS\":\"1\",\"YHJE\":\"0.00\"},{\"SYLX\":\"小灵通市话详单\",\"THSC\":\"163\",\"YSJE\":\"0.30\",\"BJQY\":\"油城通被叫号段:13\",\"HSSJ\":\"20170820153942\",\"JFJE\":\"0.30\",\"BJHM\":\"13q009907707\",\"JFCS\":\"3\",\"YHJE\":\"0.00\"}],\"error_message\":\"\",\"countByHour_hj\":[{\"SYLX\":\"48\",\"THSC\":\"3719\",\"YSJE\":\"9.10\",\"HDZS\":\"48\",\"JFJE\":\"9.10\",\"JFCS\":\"91\",\"YHJE\":\"0.00\"}]}" };
        o = JSON.parse(o.obj.replace(/,{2,}/g, ','))//去掉2个连续的逗号为1个
        alert('error='+o.error)
        alert('error_message=' + o.error_message)
        for (attr in o.countByHour_hj[0]) alert(attr + '=' + o.countByHour_hj[0][attr]);
        for (var i = 0; i < o.countByHour_mx.length; i++) alert(o.countByHour_mx[i].SYLX + '\n' + o.countByHour_mx[i].THSC + '\n' + o.countByHour_mx[i].THSC/*..更多属性..*/)
        //其他属性自己取
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题