来自asp.net weservice的jquery解析错误Json对象

时间:2012-10-02 07:04:34

标签: jquery json parsing

这是一个从asp.net webservice返回的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,"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

如何解析对象?

3 个答案:

答案 0 :(得分:0)

您将无法打印出已返回的JSON对象,并希望仅使用对象上的警报直接获取其内容。你可以做的是使用jQuery.parseJSON方法解析代码。看看:

http://api.jquery.com/jQuery.parseJSON/

答案 1 :(得分:0)

W3SCHOOLS.COM

如果我正确的话!

alert(msg[0].fullname);

会给你 马丁

答案 2 :(得分:0)

你是什么意思解析。如果你想迭代json对象.. ??

如果有的话,试试这个

success : function(msg){

     $.each(msg , function(){
        $.each(this , function(i,value){
           console.log('The value of : ' + i + ' is - ' + value);  
        });
      });
}

CHECK FIDDLE