Author

Topic: API -> blockchain.info question (Read 451 times)

full member
Activity: 221
Merit: 100
January 10, 2016, 11:00:12 AM
#3
Without replacing and only needing the first character, this code did the trick:

Code:
$json_url3 = "https://blockchain.info/da/unconfirmed-transactions?format=json";
$json3 = file_get_contents($json_url3);

$data3 = json_decode($json3);
$completehash = ($data3->txs[0]->hash);
echo substr($completehash, 0, 1) . "
";
sr. member
Activity: 345
Merit: 500
January 09, 2016, 04:41:23 PM
#2
The function 'json_decode' returns an object.
In that object you have an array of txs.
Each of those txs is, again, of type object.
You don't need to replace anything on the '$json3' string.

Code:
$json_url3 = "https://blockchain.info/da/unconfirmed-transactions?format=json";
$json3 = file_get_contents($json_url3);
$data3 = json_decode($json3);

$tx_count = count($data3->txs);
$latesttx = $data3->txs[$tx_count-1]->hash;
full member
Activity: 221
Merit: 100
January 09, 2016, 05:29:42 AM
#1
The following code (modified for your viewing pleasure) "usually" does the trick when I pull latest information I need from the blockchain.info API, but why does this not work? Is it because there are more than 1(one) line which includes a hash?

$json_url3 = "https://blockchain.info/da/unconfirmed-transactions?format=json";
$json3 = file_get_contents($json_url3);
$json3=str_replace('},

]',"}

]",$json3);
$data3 = json_decode($json3);
$latesttx = ($data3->txs->hash);

echo $latesttx;

I have tried to remove the "txs->" but no luck, any errors you see I don't?
Jump to: