Help with Json to get API value

Asked

Viewed 315 times

-1

I’m trying to get only the return of a variable of this "buy" api that would be the purchase value, but when I try it returns me the whole table, someone could enlighten me?

$data = json_decode(file_get_contents("https://broker.negociecoins.com.br/api/v3/btcbrl/ticker"));
echo "<pre>";
print_r($data);
echo "</pre>";

1 answer

0

Utilize print_r($data->buy);

  • Good morning, it didn’t work Lucas, continued without returning me anything. If I take the Buy, it returns everything, with the buy, it returns me nothing, my code looks like this. <? php $data = json_decode(file_get_contents("https://api.bitcointrade.com.br/v1/public/BTC/ticker"); echo "<pre>"; print_r($data->buy); echo "</pre>"; ?>

  • @Eduardocardosodossantos there in the question comment, you had said that it had worked '-'

  • worked with that question api, but testing with others did not work, like the one above example, I did not understand the reason, the syntax is the same.

  • @Eduardocardosodossantos I finished the API now. It doesn’t work in this other one because its return is not directly the buy: {&#xA;message: null,&#xA;data: {&#xA;high: 27200,&#xA;low: 25000,&#xA;volume: 182.71434794,&#xA;trades_quantity: 2538,&#xA;last: 25317.7,&#xA;sell: 25269.32,&#xA;buy: 25253,&#xA;date: "2018-08-08T11:36:18.909Z",&#xA;},&#xA;} There is a date inside it. Add -> In this case use print_r($data -> data -> buy)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.