我有以下結構。這是JSON.parse結果:JavaScript - 檢查json中的值
[{"model": "game.bowlinggame", "pk": 2587, "fields": {"Frame": 1, "FrameRow": 1, "Result": 10, "StrikeSpare": 2, "StrikeSpareInfo": "X", "Time": "2017-10-15T17:20:53.994Z", "GameId": 42, "StateOfGame": 1}}, {"model": "game.bowlinggame", "pk": 2588, "fields": {"Frame": 1, "FrameRow": 2, "Result": null, "StrikeSpare": null, "StrikeSpareInfo": null, "Time": "2017-10-15T17:20:53.996Z", "GameId": 42, "StateOfGame": 1}}]
我想檢查的「StateOfGame」 == 2的值。我試過,但它是錯誤的:
for (var i = 0; i < game_frame.length; i++) {
var obj = game_frame[i];
for (var key in obj){
console.log(key['fields']['StateOfGame']);
if (i['fields']['StateOfGame'] == 2){
do_something;
}
}
}
任何想法,我該怎麼辦這個?
'obj.fields.StateOfGame == 2' – awd