doudichu1358 2014-05-30 18:28
浏览 37

JSON.parse给了我对象而不是结果

I have variable in javascript which is coming from php by json_encode. While I am psrsing it with JSON.parse(variable). It alert me objects instead of actual result.

CODE:

var a = '<?php echo json_encode($over_branch_array); ?>';
a = JSON.parse(a);
alert(a);

EDIT:

basically I need to map my php array.

a = a.map(function(v){
    return { id : v.branch, text : v.branch };
});

If I will do JSON.stringify then I won't be able to do that..

  • 写回答

1条回答 默认 最新

  • doutongya8378 2014-05-30 18:30
    关注

    alert performs a toString conversion on objects before displaying them. You'll get a result like this.

    If you want to view the contents of the object, either console.log it or JSON.stringify it.

    EDIT:

    When I say use JSON.stringify I mean do it to show what is actually in the object:

    alert(JSON.stringify(a));
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料