473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to iterate over JSON array?

Hello,

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
  1. {
  2.   -49: {
  3.     -1: {
  4.          value: "6.0366"
  5.          name: "D. Aardsma"
  6.          }
  7.     -2: {
  8.          value: "7.8261"
  9.          name: "F. Abad"
  10.          }
  11.  
  12. // Lots more information
  13.  
  14.     -1438: {
  15.           value: "7.5591"
  16.           name: "J. Zumaya"
  17.           }
  18.         }
  19.       }   
  20.  
Ultimately, I want to return all of the values in this array in a list.

Here is the function I have built so far:
Expand|Select|Wrap|Line Numbers
  1. function refreshRankings( stat_id ) {
  2. var url = "/pullrankings.php?s=" + stat_id + "";
  3. $.getJSON( url,
  4.    function(data){
  5.      for ( statistic_id in data ) {
  6.         for ( player_id in data[ statistic_id ] ) {
  7.           for ( value in data[ statistic_id ][ player_id ] ) {
  8.             RankPlayers ( data[ statistic_id ][ player_id ].value );
  9.          }
  10.         }
  11.        }
  12.       } );
  13.  
I'm finding that when I output RankPlayers, I am only outputting the final value in the array.

Here is how I output the array:
Expand|Select|Wrap|Line Numbers
  1. var RankPlayers = function(array) {
  2. var div = $('<div id="rankings">'+ array +'</div>');
  3. $('#rankings').replaceWith( div );
  4.  }
  5. }
  6.  
If you know how I can alter my function to accomplish iterating over all the values in my JSON array I would very grateful!

Thanks very much.
Nov 1 '10 #1
1 4481
acoder
16,027 Expert Mod 8TB
Try using $.each to iterate over the array.
Nov 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: deko | last post by:
I have a file that contains the output of time(). A different time is on each line of the file, and each line represents a visit to the website. I want to calculate the total visits per day,...
7
by: Jacob JKW | last post by:
I need to iterate over combinations of n array elements taken r at a time. Because the value of r may vary quite a bit between program invocations, I'd like to avoid simply hardcoding r loops. I...
4
by: googleAcct | last post by:
see the following example. When I simplified the test case, I seem to be getting an error I cant explain, though the read succeeds and I go on to iterate on the JSON result. Using Firebug or other...
5
by: Tom Cole | last post by:
Let's say I have the following JSON string returned from a server-side process: { values: } I then create a JSON object from it using eval() (tell me if this is not what should be done). ...
5
by: Manish Tomar | last post by:
Hi, I know that using for in loop to iterate over array elements is a bad idea but I have a situation where it is tempting me to use it. I have a two dimensional sparse array say "arr" which...
8
by: desktop | last post by:
I am simulating a display that consists of 20x20 pixels. All pixels are per default white but I would like to be able to turn on some or all the pixels. My idea was to create a 3 dimensional...
4
by: jpuopolo | last post by:
All: I am using Python to read some records from the MySQL database. I am using the mysqldb library, and things are working well. Now, I would like to pass back the results of the query to a...
2
by: xdevel1999 | last post by:
Hi, I have the following problem: when I try to access to the array in Big object I have 'Big is not defined' but when I try to access to the function in Low object I have no error!!!! WHY?? ...
2
pradeepjain
by: pradeepjain | last post by:
i have a page post2.php which prints the json array like { page: 1, total: 239, rows: }, {id:'238',cell:}, {id:'237',cell:}, {id:'236',cell:}, {id:'235',cell:},
0
by: BaseballGraphs | last post by:
Hello, I am trying to use Ajax in order to improve the speed of my website. I am trying to pull data from a dynamic page and insert the data onto the current page. There are 3 three things I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.