?
Solved

Loop JSON Properties

Posted on 2009-07-02
3
Medium Priority
?
2,414 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

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 …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
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

765 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