Solved

Loop JSON Properties

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

691 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