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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵