drix47193 2012-04-26 13:01
浏览 60
已采纳

PHP json_encode到JS

PHP json_encode as AJAX var "result":

[{"id":"139","assettypeid":"3","name":"skin1","body":"skin1.jpg"}]

I'm trying to access each property, but I can't:

for (var i =0;i < result.length-1;i++)
{
  var item = result[i];
  console.log (item.id + item.name + item.body);
}

All I see is:

NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
...

And there are way too many iterations ... as you can see in the JSON above, there should only be 4 loops.

  • 写回答

3条回答 默认 最新

  • dongyi9298 2012-04-26 13:16
    关注

    you need to use JSON.parse

    var items = JSON.parse(result)
    

    http://www.json.org/js.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?