Solved

Loop JSON Properties

Posted on 2009-07-02
3
2,404 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
3 Comments
 
LVL 2

Accepted Solution

by:
iarla earned 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

831 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