Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to parse the json data getting both key name and value

Posted on 2013-12-22
1
Medium Priority
?
222 Views
Last Modified: 2013-12-27
I have the following JSON data.  Using JavaScript how do i parse the following JSON data getting the key name and value.   Now the area i am focusing is the DATA node in the JSON

{"total":154,"per_page":20,"current_page":1,"last_page":8,"from":1,"to":20,
"data":[{"id":1,"name":"the name","contact":"Rob"},{"id":2,"name":"the name","contact":"Joe"}]}

Open in new window

0
Comment
Question by:stargateatlantis
1 Comment
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39735299
Test page : http://jsfiddle.net/WVauu/

var json = {"total":154,"per_page":20,"current_page":1,"last_page":8,"from":1,"to":20,
"data":[{"id":1,"name":"the name","contact":"Rob"},{"id":2,"name":"the name","contact":"Joe"}]}

alert("total: " + json.total);

for(var i=0;i<json.data.length;i++) {
    var id = json.data[i]["id"];
    var name = json.data[i].name;
    var contact = json.data[i]["contact"];
    alert("id: " + id + ", name! " + name + ", contact: " + contact);
}

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

876 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