Reputation: 21
I found this little "API" that I want to take data from.
https://www.bitstamp.net/api/ticker/
Basically, I want to take the value "ask" and use it in HTML. From the 7 values there, how do I specifically target the "ask" price and nothing else? I just want the number.
The API returns
{"high": "849.00", "last": "847.59", "timestamp": "1385491132", "bid": "847.59", "volume": "31642.03534404", "low": "770.10", "ask": "848.00"}
Sorry, I know I sound horribly dumb, I am still new to this.
Upvotes: 0
Views: 37
Reputation: 39777
That data is returned as JSON string, you can use JSON.parse
to extract needed property.
Let's say you want to display value in this element:
<input type="text" id="ask" />
The code would be:
// simulated value, in reality result of API call
var sResult = '{"high": "849.00", "last": "847.59", "timestamp": "1385491132", "bid": "847.59", "volume": "31642.03534404", "low": "770.10", "ask": "848.00"}'
var jsResult = JSON.parse(sResult);
document.getElementById("ask").value = jsResult.ask;
Demo: http://jsfiddle.net/qfY6s/
Upvotes: 1