2012-03-14 13 views
2

以下の作品、私はこのようなものがある場合:私はcustinfoがリストであるようなjqueryの2次元JSON

 return Json(new { CustomerInfo = custinfo, Message = msg }); 

注意としてバックデータの2枚を渡した場合、

return Json(new { CustomerInfo = custinfo}); // defined in the controller 

    // below I define in my client script 
    jQuery.each(CustomerInfo, function() { 
       jQuery.each(this, function() { 
        // get field info from the object 
       }); 
      }); 

をしかし、そしてメッセージは、私はJSON

から取り出し情報と、次のしている私の .ajax()で文字列

です

私は上記のコードでJSON.stringifyに警告を行う場合、私は、次をゲット:私は.each() wihinデータを表示すると

[{"ID":"12","Date":"01/23/2012","City":"Clearwater","State":"FL"},{"ID":"00017-LV01-12","Date":"02/09/2012","City":"Peoria","State":"IL"},{"ID":"00010-LV01-12","Date":"06/22/2012","City":"Newport Beach","State":"CA"}] 

それは、行のコンテンツのための未定義を引っ張っています。 行の内容を表示するにはどうすればよいですか。

+1

'{はcustomerinfo = custinfo}'新しい何ですか?それは有効なJavaScriptではないようです。 –

答えて

0

あなたはこの試みることができる:

 $.each(data.CustomorInfo,function(i) { 

      $.each(this, function(key, value) { 
         alert(key +'='+ value); 
       }); 
      }); 

     }); 

ライブデモ:http://jsfiddle.net/PQcFx/18/

0

あなたのコードは私のテストで正常に動作しているように見えます。 "custinfoが" サーバー/バックエンドで定義されている方法を知らず

http://jsfiddle.net/TapfF/2/

...

$(document).ready(function() { 
    var data = { 
     "CustomerInfo": [{"ID":"12","Date":"01/23/2012","City":"Clearwater","State":"FL"},{"ID":"00017-LV01-12","Date":"02/09/2012","City":"Peoria","State":"IL"},{"ID":"00010-LV01-12","Date":"06/22/2012","City":"Newport Beach","State":"CA"}], 
     "Message": "testing123" 
    }; 

    alert(data.Message); 
    jQuery.each(data.CustomerInfo, function() { 
     alert("outer: " + this); 
     jQuery.each(this, function() { 
      alert("inner: " + this); 
     }); 
    }); 
});