dqjjw04440 2012-01-11 00:28 采纳率: 0%
浏览 78
已采纳

没有解析JSON数据?

I followed the advice here on how to use JSON.

After using

$resultAml =  json_encode($resultArray);

in PHP I get this at the client:

[{"id":"1","0":"1","title":"Facebook","1":"Facebook","url":"http://facebook.com","2":"http://facebook.com","domain":"facebook.com","3":"facebook.com","tag":"","4":""},{"id":"1","0":"1","title":"Ideeli","1":"Ideeli","url":"http://www.ideeli.com","2":"http://www.ideeli.com","domain":"ideeli.com","3":"ideeli.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Kikin","1":"Kikin","url":"http://www.kikin.com","2":"http://www.kikin.com","domain":"kikin.com","3":"kikin.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Lot18","1":"Lot18","url":"http://www.lot18.com","2":"http://www.lot18.com","domain":"lot18.com","3":"lot18.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Quora","1":"Quora","url":"http://quora.com","2":"http://quora.com","domain":"quora.com","3":"quora.com","tag":"","4":""},{"id":"1","0":"1","title":"Twitter","1":"Twitter","url":"http://twitter.com","2":"http://twitter.com","domain":"twitter.com","3":"twitter.com","tag":"","4":""}] 

That looks like valid JSON according to json.org

Howwever,

When I parse it on the client side using

JSON.parse

I get this result:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Looks like one [object Object] for each entry in the table.

What is object Object?

Where did I go wrong here? Or if not how do I get to the data in the result?

  • 写回答

3条回答 默认 最新

  • drbuowqe02101 2012-01-11 00:31
    关注

    You have the data, you just misunderstand how it's being displayed. The default string representation of any JavaScript Object, which is what JSON {...} values are, is just [object Object]. If you try to access the properties of the objects you will see that the data you expect is there:

    var input = '[{"id":"1","0":"1","title":"Facebook","1":"Facebook","url":"http://facebook.com","2":"http://facebook.com","domain":"facebook.com","3":"facebook.com","tag":"","4":""},{"id":"1","0":"1","title":"Ideeli","1":"Ideeli","url":"http://www.ideeli.com","2":"http://www.ideeli.com","domain":"ideeli.com","3":"ideeli.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Kikin","1":"Kikin","url":"http://www.kikin.com","2":"http://www.kikin.com","domain":"kikin.com","3":"kikin.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Lot18","1":"Lot18","url":"http://www.lot18.com","2":"http://www.lot18.com","domain":"lot18.com","3":"lot18.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Quora","1":"Quora","url":"http://quora.com","2":"http://quora.com","domain":"quora.com","3":"quora.com","tag":"","4":""},{"id":"1","0":"1","title":"Twitter","1":"Twitter","url":"http://twitter.com","2":"http://twitter.com","domain":"twitter.com","3":"twitter.com","tag":"","4":""}]';
    var data = JSON.parse(input);
    alert(data[0].title); // displays "Facebook"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用