[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to parse JSON object

Posted on 2007-10-16
3
Medium Priority
?
373 Views
Last Modified: 2012-05-05
I have something that has me stumped. I would appreciate some help.

I am using prototype.js to do an AJAX call and am returning the result as JSON. Here is a sample:

{ "location": [
      {"value":"5", "name":"New York"},
      {"value":"4", "name":"Jersey"}
]}

I need to know how to parse this data. I have look and looked for example and can not find anything that works.

Thanks for the help.
0
Comment
Question by:td234
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1500 total points
ID: 20087303
Have you looked at http://www.json.org/js.html

myjson.location[0].name == "New York";
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20087943
What exactly do you mean by parse it?  What do you need from it or how do you want to work it (i.e. loop through all, get specific item's value, etc)?

A simple example would be script like ...

for (var i=0; i<listLocation.location.length; i++) {
      document.write(listLocation.location[i].name + ' | ' + listLocation.location[i].value + '<br />');
}

This assumes that the json above is entered or "evaled" into a variable called listLocation.

Let me know if you have a question or how this helps.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20087948
Oops.  Too late. :)

bol
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

830 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