如何像对象一样操纵Json响应? [英] how to manipulate Json response like an object?
本文介绍了如何像对象一样操纵Json响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的jQuery.ajax返回JSon对象.我首先阅读其他文章.但他们的回应文字不喜欢我的. 我的回复内容:来自萤火虫回复
my jQuery.ajax return JSon object. I firstly read other articles. but their response text not likes mine. My Response content: from firebug response
{"item":"[{\"country\":\"USA\",\"lan\":\"EN\"},{\"country\":\"Turkiye\",\"lan\":\"TR\"}]"}
现在我要提醒countryName:
Now i trying to alert 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.试试这个.
The value of item is a string. Thus you first need to parse it as json. Try this.
$("#jsonResponse").html(msg);
var item = jQuery.parseJSON(msg.item)
$.each(item, function(i, d) {
alert(this.country);
debugger;
});
},
这篇关于如何像对象一样操纵Json响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文