私は本当にマストを調べていませんjQuery + JSON
。だからここに私の試みがあります。
http://ddragon.leagueoflegends.com/cdn/4.14.2/data/en_US/rune.json
リーグオブレジェンドルーンのデータの配列である:からデータを取得したいと思います。私が取得しているよname
、description
、image -> w y x
そしてstats
私のプロジェクトで使用されます。
私は現在これを持っています:
$(document).ready(function() {
$.getJSON("http://ddragon.leagueoflegends.com/cdn/4.14.2/data/en_US/rune.json", function(data){
$.each(data, function (index, value) {
console.log(value[5001]); //<--- this the ID for one of the runes, to test if it is working
});
});
});
これは出力です:
あなたが見ることができるように、name
、description
、image -> w, x, y
とstats
表示され、どのように私はそれが各1用(クローム用)コンソールでこれらを置くことになるだろうか?
うまくいけば、あなたたちは助けることができます。
あなたは本当にあなたが必要なものを手に入れることに近づいています。問題は、$。eachループが、必要なものを取得する前にいくつかのJSONキー/値をループしていることです。
JSONオブジェクトにはドット表記でアクセスし、以下に示すように各レベルを下に移動できます。お役に立てれば。
$.getJSON("http://ddragon.leagueoflegends.com/cdn/4.14.2/data/en_US/rune.json", function(response){
console.log(response); // Has keys for type, version, data, basic
// Data is an array of elements
console.log(response.data[5001]);
// Each entry has properties you access like this.
console.log(response.data[5001].name);
console.log(response.data[5001].description);
console.log(response.data[5001].image.x);
console.log(response.data[5001].stats);
});
編集
データ配列を反復処理するには、response.dataに対して$ .eachを実行します。
$.each(response.data, function (index, entry) {
console.log(entry.name);
console.log(entry.description);
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加