So, I want to make my site check the bitcoin prices. I do that with virwox. So, I send a curl to http://api.virwox.com/api/json.php?method=getBestPrices&symbols[0]=BTC/SLL
.
That gives me this:
{"result":[{"symbol":"BTC\/SLL","errorCode":"OK","bestBuyPrice":"983021","bestSellPrice":"1009989"}],"error":null,"id":""}
Now, I want the bestBuyPrice
. So, I runned a json_decode
on my $output
. Then my $output
is an array. So, I did json_encode("$output["result"]")
to see what will come out of that. It gave me this:
[{"symbol":"BTC\/SLL","errorCode":"OK","bestBuyPrice":"983021","bestSellPrice":"1009989"}]
So, I tought if I do json_decode("$output["bestBuyPrice"]")
I would get it, but I didn't. What I got was: null
. How can I fix this?
Here is my full code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.virwox.com/api/json.php?method=getBestPrices&symbols[0]=BTC/SLL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$decode = json_decode($output, true);
$encode = json_encode($decode["result"]["bestBuyPrice"], true);
echo $encode; // Gives null
$koop = $decode["result"]["bestBuyPrice"]; // No result
$verkoop = $decode["result"]["bestSellPrice"]; // No result
echo $koop . "<br />".$verkoop;
?>
Thanks!