1

how will i be able to get a single value out of BTC-e API. This is the current API:

https://btc-e.com/api/3/ticker/btc_usd

As you can see, it shows lots of information. What can i do so that i will only get
--> "last":284.323 <-- this number?

Thank you!

1

Well that depends on what language you are using to parse the JSON.

The output for the API is in JSON format (JavaScript Object Notation). This notation is very common in the API space and when reading raw bitcoin transactions and blockchain data. When you query address information in bitcoin core console it is in JSON format. Think of it as a set of arrays. If you have an array of "Food" and that array contains "Fruit", "JunkFood", and "Snacks", and each of these arrays contain additional values within them. So if you wanted to access "apple" it would be under Food -> Fruit -> Apple.

With the BTC-e API JSON response it gives you the category first of "btc_usd" and then within that array is "high", "low", "avg", "last", etc. So in order to only select "last" it would be under btc_usd -> last.

I typically use PHP and it's quite simple to do. Here's a phpfiddle: http://phpfiddle.org/lite/code/jsah-t4dv

<?php
$url = "https://btc-e.com/api/3/ticker/btc_usd";
$decode = json_decode(file_get_contents($url), true);
$price = $decode["btc_usd"]["last"];
echo $price;
?>
  • 1
    Thank you very much for your detailed and informative answer. Not only do i know how to do it now, i also know what i am doing because of your explanation. Thanks – Z3br3 Oct 25 '15 at 16:19
  • @Z3br3 You're welcome! Please consider marking my response as the correct answer :) – m1xolyd1an Oct 25 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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