I am trying to iterate over a JSON array using JQuery's .getJSON method and am requiring assistance building the javascript function to iterate and return all values in my array.
My JSON array takes the following form:
Expand|Select|Wrap|Line Numbers
- {
- -49: {
- -1: {
- value: "6.0366"
- name: "D. Aardsma"
- }
- -2: {
- value: "7.8261"
- name: "F. Abad"
- }
- // Lots more information
- -1438: {
- value: "7.5591"
- name: "J. Zumaya"
- }
- }
- }
Here is the function I have built so far:
Expand|Select|Wrap|Line Numbers
- function refreshRankings( stat_id ) {
- var url = "/pullrankings.php?s=" + stat_id + "";
- $.getJSON( url,
- function(data){
- for ( statistic_id in data ) {
- for ( player_id in data[ statistic_id ] ) {
- for ( value in data[ statistic_id ][ player_id ] ) {
- RankPlayers ( data[ statistic_id ][ player_id ].value );
- }
- }
- }
- } );
Here is how I output the array:
Expand|Select|Wrap|Line Numbers
- var RankPlayers = function(array) {
- var div = $('<div id="rankings">'+ array +'</div>');
- $('#rankings').replaceWith( div );
- }
- }
Thanks very much.