我的 jQuery.ajax 返回 JSon 对象。我首先阅读了其他文章。但他们的回复文字不喜欢我的。 我的回复内容:来自 firebug 回复
{"item":"[{\"country\":\"USA\",\"lan\":\"EN\"},{\"country\":\"Turkiye\",\"lan\":\"TR\"}]"}
现在我试图提醒countryName:
$('#loadData').click(function() {
$.ajax({
type: "POST",
url: "WS/myWS.asmx/getDaa",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#jsonResponse").html(msg);
$.each(msg.item, function(i, d) {
alert(this.country);
debugger;
});
},
});
});
但它正在警告“未定义”
最佳答案
item 的值是一个字符串。因此,您首先需要将其解析为 json。试试这个。
$("#jsonResponse").html(msg);
var item = jQuery.parseJSON(msg.item)
$.each(item, function(i, d) {
alert(this.country);
debugger;
});
},
关于jquery - 如何像对象一样操作Json响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2454952/