来自asp.net weservice的jquery解析Json对象时出错
这是从asp.net Web服务返回的JSON对象来自asp.net weservice的jquery解析Json对象时出错,jquery,json,parsing,Jquery,Json,Parsing,这是从asp.net Web服务返回的JSON对象 [{"fullname":"martin","isAdmin":false,"Latitude":47,"Longitude":-124,"isOnline":false}, {"fullname":"melvyn","isAdmin":false,"Latitude":47,"Longitude":-124,"isOnline":true}, {"fullname":"simon","isAdmin":false,"Latitude":47,
[{"fullname":"martin","isAdmin":false,"Latitude":47,"Longitude":-124,"isOnline":false},
{"fullname":"melvyn","isAdmin":false,"Latitude":47,"Longitude":-124,"isOnline":true},
{"fullname":"simon","isAdmin":false,"Latitude":47,"Longitude":-124,"isOnline":false}]
当我在jquery中使用警报时
$(function () {
$("#btnShow").click(function () {
$.ajax(
{
type: "POST",
url: "WS_PfaMembers.asmx/GetPFAMembersForMap",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
},
failure: function (msg) {
alert('error');
}
});
});
});
msg
的警报发出object-object
如何解析该对象?您将无法打印出返回的JSON对象,只需对该对象发出警报即可直接获取该对象的内容。您可以做的是使用jQuery.parseJSON方法解析代码。看看: 如果我是对的
alert(msg[0].fullname);
将为您提供马丁你说的解析是什么意思。如果要在json对象上迭代 如果是这样,试试这个
success : function(msg){
$.each(msg , function(){
$.each(this , function(i,value){
console.log('The value of : ' + i + ' is - ' + value);
});
});
}
尝试console.log(msg)
并查看JavaScript控制台。这将显示对象的详细结构。