1

私はファイルtest.phpを持っています

{"1":{"PLAYER1":"PLAYER_ID3","HEALTH1":90.625,"PLAYER2":"PLAYER_ID5","HEALTH2":89.0625},"2":{"PLAYER1":"PLAYER_ID3","HEALTH1":81.25,"PLAYER2":"PLAYER_ID5","HEALTH2":78.125},"3":{"PLAYER1":"PLAYER_ID3","HEALTH1":71.875,"PLAYER2":"PLAYER_ID5","HEALTH2":67.1875},"4":{"PLAYER1":"PLAYER_ID3","HEALTH1":62.5,"PLAYER2":"PLAYER_ID5","HEALTH2":56.25},"5":{"PLAYER1":"PLAYER_ID3","HEALTH1":53.125,"PLAYER2":"PLAYER_ID5","HEALTH2":45.3125},"6":{"PLAYER1":"PLAYER_ID3","HEALTH1":43.75,"PLAYER2":"PLAYER_ID5","HEALTH2":34.375},"7":{"PLAYER1":"PLAYER_ID3","HEALTH1":34.375,"PLAYER2":"PLAYER_ID5","HEALTH2":23.4375},"8":{"PLAYER1":"PLAYER_ID3","HEALTH1":25,"PLAYER2":"PLAYER_ID5","HEALTH2":12.5},"9":{"PLAYER1":"PLAYER_ID3","HEALTH1":15.625,"PLAYER2":"PLAYER_ID5","HEALTH2":1.5625},"10":{"PLAYER1":"PLAYER_ID3","HEALTH1":6.25,"PLAYER2":"PLAYER_ID5","HEALTH2":-9.375},"11":{"PLAYER1":"PLAYER_ID3","HEALTH1":-6.875,"PLAYER2":"PLAYER_ID4","HEALTH2":89.0625},"12":{"PLAYER1":"PLAYER_ID1","HEALTH1":86.875,"PLAYER2":"PLAYER_ID4","HEALTH2":76.875},"13":{"PLAYER1":"PLAYER_ID1","HEALTH1":73.75,"PLAYER2":"PLAYER_ID4","HEALTH2":64.6875},"14":{"PLAYER1":"PLAYER_ID1","HEALTH1":60.625,"PLAYER2":"PLAYER_ID4","HEALTH2":52.5},"15":{"PLAYER1":"PLAYER_ID1","HEALTH1":47.5,"PLAYER2":"PLAYER_ID4","HEALTH2":40.3125},"16":{"PLAYER1":"PLAYER_ID1","HEALTH1":34.375,"PLAYER2":"PLAYER_ID4","HEALTH2":28.125},"17":{"PLAYER1":"PLAYER_ID1","HEALTH1":21.25,"PLAYER2":"PLAYER_ID4","HEALTH2":15.9375},"18":{"PLAYER1":"PLAYER_ID1","HEALTH1":8.125,"PLAYER2":"PLAYER_ID4","HEALTH2":3.75},"19":{"PLAYER1":"PLAYER_ID1","HEALTH1":-5,"PLAYER2":"PLAYER_ID4","HEALTH2":-8.4375},"20":{"PLAYER1":"PLAYER_ID2","HEALTH1":85.3125,"PLAYER2":"PLAYER_ID6","HEALTH2":87.5},"21":{"PLAYER1":"PLAYER_ID2","HEALTH1":70.625,"PLAYER2":"PLAYER_ID6","HEALTH2":75},"22":{"PLAYER1":"PLAYER_ID2","HEALTH1":55.9375,"PLAYER2":"PLAYER_ID6","HEALTH2":62.5},"23":{"PLAYER1":"PLAYER_ID2","HEALTH1":41.25,"PLAYER2":"PLAYER_ID6","HEALTH2":50},"24":{"PLAYER1":"PLAYER_ID2","HEALTH1":26.5625,"PLAYER2":"PLAYER_ID6","HEALTH2":37.5},"25":{"PLAYER1":"PLAYER_ID2","HEALTH1":11.875,"PLAYER2":"PLAYER_ID6","HEALTH2":25},"26":{"PLAYER1":"PLAYER_ID2","HEALTH1":-2.8125,"PLAYER2":"PLAYER_ID6","HEALTH2":12.5}}

および別のファイル: http://jsfiddle.net/MT3Qf/

開始時に表示されます: 現在のプレーヤー:PLAYER_ID2 PLAYER_ID3 ...

しかし、現在のプレーヤーが player_id2 であるというのは事実ではありません。現在のプレーヤーは id3 です。どうすればこれを修正できますか?

4

1 に答える 1

2

データを配列のように扱いたいようですが、そうではありません。たくさんのプロパティを持つオブジェクトです。そのため、 などの関数によって返される順序は$.each()保証されません。

おそらく、JSON を変更して、配列として動作させたいものを配列として表す必要があります。

于 2012-11-30T00:00:42.023 に答える