读jQuery的JSON结构 - 不能得到它的工作 [英] Reading jQuery JSON Structure - cant get it to work
本文介绍了读jQuery的JSON结构 - 不能得到它的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的JSON结构,正在从一个AJAX调用返回(伪值)
I have the following JSON structure, being returned from an AJAX call (pseudo values)
[
{
"id":"14",
"product_title":"Foo Bar v1.2",
"discount":"10% Off - New price: $97",
"vendor":"foobar"
}
]
下面是我的AJAX程序。
Here is my AJAX routine.
$.post('Ajax.php',function(res){
alert(res.product_title);
});
},'json');
然而,警报说未定义,即使它显然不是(萤火虫)。
However, the alert says "Undefined", even though it is clearly not (Firebug).
我试着做一个 $每();
上的资源,它出现的唯一钥匙中有0
I tried doing a $.each();
on the res, and it appears the only "key" in there is "0".
我在做什么错在这里?是它的方式,我处理的结构?干杯!
What am I doing wrong here? Is it the way I am processing the structure? Cheers!
推荐答案
尝试:
var j = res.pop(); // this will extract the `object` form the `array`
console.log(j.product_title);
您也可以这样写:
res.pop().product_title;
这篇关于读jQuery的JSON结构 - 不能得到它的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文