Cant get a specific value in JSON/PHP

0 votes

I am trying to pull one single piece of data from a json encoded string. I managed to get the string into php's jason format, but I dont understand how to display the exact data I want

This is the code:

<?PHP
$return = file_get_contents("https://api.chain.com/v2/bitcoin/transactions/76e6f17cb940745255e2b8439eea5dae945a    b148f1fbba98a9fb99c9a5801320?api-key-id=ae7317a1cd4ff0d12e49a77bfd8b9dec");
var_dump(json_decode($return));
echo $return[0]["confirmations"]; //one of my many attempts to get the info, also tried without the leading zero, and different numbers. I understand arrays, I just dont understand how the json data is formatted inside the array.
?>

Output:

object(stdClass)#1 (11) {
  ["hash"]=>
  string(64) "76e6f17cb940745255e2b8439eea5dae945ab148f1fbba98a9fb99c9a5801320"
  ["block_hash"]=>
  string(64) "00000000000000001646d024d4622a0e4a5c06299d7d776de041bc9c317be1f8"
  ["block_height"]=>
  int(329486)
  ["block_time"]=>
  string(20) "2014-11-11T02:10:21Z"
  ["chain_received_at"]=>
  string(24) "2014-11-11T02:05:48.259Z"
  ["confirmations"]=>
  int(2896)
  ["lock_time"]=>
  int(0)
  ["inputs"]=>
  array(2) {
    [0]=>
    object(stdClass)#2 (7) {
      ["transaction_hash"]=>
      string(64) "76e6f17cb940745255e2b8439eea5dae945ab148f1fbba98a9fb99c9a5801320"
      ["output_hash"]=>
      string(64) "4f7b6066396e422f1cabd60767093ec6fb4480b60f206c408ad50895541bc023"
      ["output_index"]=>
      int(0)
      ["value"]=>
      int(144475)
      ["addresses"]=>
      array(1) {
        [0]=>
        string(34) "1HPvAS96JXYUuLDs5CKNh61SvH6NJT1ykH"
      }
      ["script_signature"]=>
      string(213) "304602210087289ed01fd7d04e3c7eb5c38ea1944cbc3789658a1122610079a4f0421e2426022100fca6f5f4623bbac131f06ebdc7389ea0c76b4355da9508ecc7b02107385ee79d01 029a79a3cf6f8b90b7c1210e593a21e46c81ffbbe544eb2ab3ebbd89f33e4f8b2e"
      ["sequence"]=>
      int(4294967295)
    }
    [1]=>
    object(stdClass)#3 (7) {
      ["transaction_hash"]=>
      string(64) "76e6f17cb940745255e2b8439eea5dae945ab148f1fbba98a9fb99c9a5801320"
      ["output_hash"]=>
      string(64) "22de0dbb8d72fac9a6e8775f6f80fa3fc991c41d33fcd5081acb49c0479f2a62"
      ["output_index"]=>
      int(1)
      ["value"]=>
      int(7390022)
      ["addresses"]=>
      array(1) {
        [0]=>
        string(34) "158kR5o6EWWhFEZfLqGDvkgfoyi2Ep2fhA"
      }
      ["script_signature"]=>
      string(209) "304402205e2f36c9c22e02767e3accc8bc609b74d5a23c58e4a8edbac24cb4baf1e3feaa022043ad33becd57c5dee03fd1c1d8be1524281f6f49ba1e44a1a2b340f89554c42d01 031181694e14973f71d45f5f3ab73ee0f30dfa3f488bf53c44e46cf9f4f3d3d722"
      ["sequence"]=>
      int(4294967295)
    }
  }
  ["outputs"]=>
  array(2) {
    [0]=>
    object(stdClass)#4 (9) {
      ["transaction_hash"]=>
      string(64) "76e6f17cb940745255e2b8439eea5dae945ab148f1fbba98a9fb99c9a5801320"
      ["output_index"]=>
      int(0)
      ["value"]=>
      int(144475)
      ["addresses"]=>
      array(1) {
        [0]=>
        string(34) "1P5rwnk3GYbxgpxN9M9EziLrpvoih4c8JC"
      }
      ["script"]=>
      string(85) "OP_DUP OP_HASH160 f23e1f6dd21bab989f18c14f26bf37b4e2372eef OP_EQUALVERIFY OP_CHECKSIG"
      ["script_hex"]=>
      string(50) "76a914f23e1f6dd21bab989f18c14f26bf37b4e2372eef88ac"
      ["script_type"]=>
      string(10) "pubkeyhash"
      ["required_signatures"]=>
      int(1)
      ["spent"]=>
      bool(false)
    }
    [1]=>
    object(stdClass)#5 (9) {
      ["transaction_hash"]=>
      string(64) "76e6f17cb940745255e2b8439eea5dae945ab148f1fbba98a9fb99c9a5801320"
      ["output_index"]=>
      int(1)
      ["value"]=>
      int(7380022)
      ["addresses"]=>
      array(1) {
        [0]=>
        string(34) "1DpY5Mu2qTNkwsnPwgqFnaZ1Kq7GpKDboy"
      }
      ["script"]=>
      string(85) "OP_DUP OP_HASH160 8c9efff6e8500a36c16a939054a333d81ef23166 OP_EQUALVERIFY OP_CHECKSIG"
      ["script_hex"]=>
      string(50) "76a9148c9efff6e8500a36c16a939054a333d81ef2316688ac"
      ["script_type"]=>
      string(10) "pubkeyhash"
      ["required_signatures"]=>
      int(1)
      ["spent"]=>
      bool(true)
    }
  }
  ["fees"]=>
  int(10000)
  ["amount"]=>
  int(7524497)
}
{
Sep 11, 2018 in Blockchain by digger
• 27,620 points
53 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Convert the json-string to a php-array and save it in a variable. Then use it like any other array to get values from it. Like this:

$return = file_get_contents('http://etc.com/');
$decoded_return = json_decode($return);

echo $decoded_return['confirmations']; //Make sure the key exists, obviously
answered Sep 11, 2018 by slayer
• 29,040 points

Related Questions In Blockchain

+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
1,503 views
0 votes
1 answer
0 votes
1 answer

Get specific JSON data value using array from Coin Market Cap API

use inArray function. example: $.getJSON("//api.coinmarketcap.com/v1/ticker/?limit=0", function(data) { ...READ MORE

answered Oct 8, 2018 in Blockchain by Omkar
• 65,810 points
33 views
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 16,450 points
589 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
42 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
60 views
0 votes
1 answer

jsonRPCClient Error with php variables

All you have to do is change ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
26 views
0 votes
1 answer

How to get amount of bitcoins in php?

I’ve tried this code and it works: <?php function ...READ MORE

answered Aug 24, 2018 in Blockchain by slayer
• 29,040 points
31 views
0 votes
1 answer

Can't open a to big .csv file in python

You can't "split a file", but you can read ...READ MORE

answered Sep 3, 2018 in Blockchain by slayer
• 29,040 points
31 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.