[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Loop JSON Properties

Posted on 2009-07-02
3
Medium Priority
?
2,415 Views
Last Modified: 2013-11-08
Hello Experts -

I am getting a JSON object using JQuery and .getJSON function.  

Is there a way to loop through object's properties and retrieve the name of each property?

I'm new to JSON, so an examples would be great.

Thanks.
0
Comment
Question by:soapygus
[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
3 Comments
 
LVL 2

Accepted Solution

by:
iarla earned 2000 total points
ID: 24768736
Hi there

Have a look at the following link

http://stackoverflow.com/questions/684672/loop-through-json-object
0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24770341
You can try $.each() for this.

var students = {student1:{name:'Mr A', fathername:'Father A'},student2:{name:'Mr B', fathername:'Father B'},student3:{name:'Mr C', fathername:'Father C'}};
$(function(){
jQuery.each(students, function(i, val) {
      alert(i+' name: '+val.name);
    });
});

Open in new window

0
 

Author Closing Comment

by:soapygus
ID: 31599410
Here's what worked in my solution (where 'data' is the JSON object)
 for (var key in data) {
                                if (data.hasOwnProperty(key)) {
                                    $('#findMe').append(key + '');
                                }
                            }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

650 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