Solved

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

Posted on 2007-12-05
2
910 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now