JSON help

I’m trying to grab the addresses used in a transaction with PHP and JSON, but I’m having no luck. I’ve need to set a variable in PHP but I can’t seem to actually get the data. I’ve tried:

$newjson = file_get_contents($url);
$newobj = json_decode($newjson);
    echo $newobj['addresses[0]'];

But that doesn’t return anything. Help?

bmp02050 can you paste the url you are requesting, or what return data you are getting?

$newjson = file_get_contents($url);
$newobj = json_decode($newjson, true);
    echo $newobj['addresses'][0];

Convertor http://live.reddcoin.com/api/tx/395fbcaddb90fce4bbc8427af60cacb782b57ab8ddf757e9859efcae200a602c is the transaction. There are 2 addresses, one to RsNsTKFUiFVzYpLWxm6GuCFyY2zesifTTU and one to RqUCyAonmBiHT29wi8ETuerik5BDQ35835 but nothing shows up. The page is blank.

1 Like

bmp02050 found 3 addresses total.

$data = json_decode(file_get_contents('http://live.reddcoin.com/api/tx/395fbcaddb90fce4bbc8427af60cacb782b57ab8ddf757e9859efcae200a602c'), true);
echo "<pre>";
echo "</pre>";

$address_1 = $data['vin'][0]['addr'];
$address_2 = $data['vout'][0]['scriptPubKey']['addresses'][0];
$address_3 = $data['vout'][1]['scriptPubKey']['addresses'][0];

echo "address 1: ".$address_1;
echo "address 2: ".$address_2;
echo "address 3: ".$address_3;

Was able to get all 3 addresses with very similar method as Convertor , Although I prefer objects over arrays (;

$data = json_decode(file_get_contents("http://live.reddcoin.com/api/tx/395fbcaddb90fce4bbc8427af60cacb782b57ab8ddf757e9859efcae200a602c"));

echo "First: " . $data->vin[0]->addr . "<br />";
echo "Second: " . $data->vout[0]->scriptPubKey->addresses[0] . "<br />";
echo "Third: " . $data->vout[1]->scriptPubKey->addresses[0] . "<br />";

1 Like

iisurge Thanks!