?
Solved

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

Posted on 2007-12-05
2
Medium Priority
?
952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

649 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