Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a JSON array that is output from an API. The array is similar to this: http://pastebin.com/pHH977Uj
What is the most delicate way to pick out the various prices in my javascript? I'd prefer them to be variables or in an array. I'm fairly new to programming outside of html/php for web, so bear with me D:
I've been bugging around this problem for about a week now.
EDIT:
Thanks for the fast responses! What I'm looking for are basically a way to turn every price into a variable similar to coke-usd, pepsi-euro or salty-euro. I don't necessarily need anything else, since I'm only looking to pick out the price of each product in two different currencies. Also, the JSON is as it is, I get it off of an external website, so not much I can do about the structure :/

share|improve this question
1  
What have you tried, what is your actual problem? And how do you want to reduce the structure without loosing information? –  Bergi Sep 18 '12 at 13:23
    
how do you want to adress them ? by price/name/currency/type/... be more specific about what you want exactly –  jb10210 Sep 18 '12 at 13:24
    
If this data structure has any semblance to what you really need I believe you will find it severely lacking in short order. Instead of product/currency/product_variety, you probably want product/product_variety/currency –  George Jempty Sep 18 '12 at 13:29

1 Answer 1

up vote 2 down vote accepted

First, the link shows a json object, not an array. Second, you should always handle json with

var obj = JSON.parse(jsonString);

from there, you can access the properties as usual

var sodas = obj.soda.usd; // obj, soda, and usd are all objects

and then you can get each key value pair.

 // sodas is an object too, its values are arrays
for (var soda in sodas) {
   console.log (soda, prices.soda[0]);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.