Ben
Ben

Reputation: 369

Get JSON object from URL using javascript

I'm trying to get the value of the first 'price' field at the url:

http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132

I am currently using the following code to do so:

getJSON('http://pubapi.cryptsy.com/api.php? 
method=singleorderdata&marketid=132').then(function(data) {
var final = (data.return.DOGE.sellorders.price * totalcost) * 0.985
var finished = final.toFixed(8)

I have a strong feeling that I have done this bit wrong:

data.return.DOGE.sellorders.price

Any ideas?

Thanks!

Upvotes: 0

Views: 116

Answers (1)

Dhiraj
Dhiraj

Reputation: 33618

data.return.DOGE.sellorders[0].price because sellorders is an array

$.getJSON('http://jsbin.com/pudoki/1.json', function(data){
  alert(data.return.DOGE.sellorders[0].price);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Upvotes: 1

Related Questions