我正在尝试打印“消息”
JSON:
[{"outcome":false,"message":"This is the message"}]
我尝试了三件事,以下是它们的结果...
console.log(msg)
=> [{"outcome":false,"message":"您的帐户正在等待 Beta 激活"}]
(这是很好)
var x = $.parseJSON(msg);
console.log(x)
给我一个对象
console.log(x.message)
给我 undefined
如果不是这样的话,访问 msg.message
的正确方法是什么?
最佳答案
你有一个数组中的对象。使用索引0
。
x[0].message;
<小时/>
如果您预计数组中会有更多对象,则可以使用 $.each
迭代该数组。
$.each(x, function(i, obj) {
console.log(obj.message);
});
关于javascript - jQuery 给我 "undefined"回显 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13281144/