Solved

Newbie to JSON use from javascript - JSON iteration and getting values

Posted on 2007-12-05
2
928 Views
Last Modified: 2010-04-21
Hello,

I am new to JSON and I am using the prototype library by the way.

the data that a recieve from my ajax query looks like this
{'0':'string1','1':'string2'}

I will not know any of the elements at query time but what I do need to do is find out the number of elements and to be able to iterate throught them to get all of the values.

How do I do that using JSON notation.

Thanks,

David


0
Comment
Question by:dmontgom
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 20416107
<script type="text/javascript">
var result=null;

//...
eval("result=" + JSONString + ";");
if(result)
{
 for( var i in result )
  alert( i + "=" + result[i] );
}
where the "..." is the code that makes the request to the server and JSONString is the data you are getting from the server in JSON format.
0
 

Author Closing Comment

by:dmontgom
ID: 31413000
Way to go....thanks for the quick response.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Validating Date 4 28
RSS FEED - PROPERLY FORMATTED URL 2 25
Echo'd values in dropdowns 6 27
How to add custom html-5 element to a dynamically generated link? 4 23
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question