PHP json_encode到JS [英] PHP json_encode to JS

查看:301
本文介绍了PHP json_encode到JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP json_encode作为AJAX变量结果":

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);
}

我所看到的是:

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

迭代太多了...如上面的JSON所示,应该只有4个循环.

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

推荐答案

您需要使用JSON.parse

you need to use JSON.parse

var items = JSON.parse(result)

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

这篇关于PHP json_encode到JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆