2016-10-29 12 views
0

"名前"と "チーム"と "位置"などの値を取得したいのですが、2つのループで正しく行う必要があることはわかりますか?任意のヒントのjquery - 多次元配列を実行する(Json

[ 
{"name":"R. Burnell","team":"Dortmund","position":"GK","points":"4"}, 
{"name":"R. Weidenfeller","team":"Dortmund","position":"GK","points":"45"} 
] 

おかげで...

function getPlayersOfChosenTeam(team, nameOfPlayersTable){ 

$.ajax({ 
    url:'getPlayersOfChosenTeam.php', 
    type:'post', 
    data:{'team':team, 'nameOfPlayersTable':nameOfPlayersTable}, 
    success: function (res) { 

     console.log(res); 


    } 
}); 
} 

と私の解像度のデータは次のようになります。まさに私のコードは次のようになりますか...

知っています

挨拶

+0

なし、JSON文字列は、私はあなたがおそらくを見ている必要があり、関数の名前に基づいて、以下の文字列... – nbg15

+0

を掲載解像度コンテンツであります:[非同期呼び出しから応答を返すにはどうすればいいですか?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas

+0

私の説明で間違って申し訳ありません... – nbg15

答えて

0

実際には、あなたは1つのループが必要なので、あなたは配列osオブジェクトを持っています。ループトラフへ

for(var i = 0; i < res.length; i++) { 
    console.log('name: ', res[i].name); 
    console.log('team: ', res[i].team); 
    console.log('position: ', res[i].position); 
    console.log('points: ', res[i].points); 
} 
0

あなたのデータ、あなたがこのようなjquerys .each()関数で使用できます。これは、ソリューションです

$.ajax({ 
    url:'getPlayersOfChosenTeam.php', 
    type:'post', 
    data:{'team':team, 'nameOfPlayersTable':nameOfPlayersTable}, 
    success: function (res) { 

      $(res).each(function(index, item){ 
      console.log(item.name); 
      console.log(item.team); 
      console.log(item.points); 
      }); 

    } 
0

を! ;)Json.parse()と は

$.each(JSON.parse(res), function(idx, obj) {  
    alert(obj.name); 
});