从文件中读取JSON数组,无法访问数组或推入i

时间:2015-08-16 04:55:26

标签: javascript json

CatC

json文件

$.getJSON(geocodingAPI, function (json) {
var array = [];

for (var key in json) {

    var item = json[key];

    array.push({

       name: item.player.player-name ,
       position: item.player.player-stats.position,
       yd: item.player.player-stats.passing-yards,
       pa: item.player.player-stats.passing-touchdowns,

    });            
}
}    
);

1 个答案:

答案 0 :(得分:0)

拳头使你的JSON有效。在这里我更新了有效的JSON:

{
"players": {
    "player": {
        "player-name": "Aaron Rodgers",
        "player-stats": {
            "position": "QB",
            "passingYards": 327,
            "passingTouchdowns": 3
        }
    }
}
}