如何使用PHP函数从JSON中提取数据?

时间:2018-02-04 10:59:29

标签: php json

我有JSON:

{
    "hex": "01000000a0d8765a010adf2ec953a98e7c8821315b47882b6ddd01f272d5fa2c5224882ae2b53c9f8e0100000048473044022052ab88dd84a5349914f65996317bf8f82afcd25b3b794e9abe7c24d06467443f02205edf9d43f407730dcfe4bf7a777b9b988eb4f62fc5f68c5c8652f3fe2f62ffc601ffffffff0300000000000000000040cb89cd0b00000023210377c08de701f9e9d4a72a6d5cd753040f5bf334c13dbeccdbb2a7d3a56b964951ac150ba0cd0b00000023210377c08de701f9e9d4a72a6d5cd753040f5bf334c13dbeccdbb2a7d3a56b964951ac00000000",
    "txid": "3b954602091718aa86bcab9c0196fa0f0072d0461cfff086382b439be1d89067",
    "version": 1,
    "time": 1517738144,
    "locktime": 0,
    "vin": [
        {
            "txid": "8e9f3cb5e22a8824522cfad572f201dd6d2b88475b3121887c8ea953c92edf0a",
            "vout": 1,
            "scriptSig": {
                "asm": "3044022052ab88dd84a5349914f65996317bf8f82afcd25b3b794e9abe7c24d06467443f02205edf9d43f407730dcfe4bf7a777b9b988eb4f62fc5f68c5c8652f3fe2f62ffc601",
                "hex": "473044022052ab88dd84a5349914f65996317bf8f82afcd25b3b794e9abe7c24d06467443f02205edf9d43f407730dcfe4bf7a777b9b988eb4f62fc5f68c5c8652f3fe2f62ffc601"
            },
            "sequence": 4294967295
        }
    ],
    "vout": [
        {
            "value": 0,
            "n": 0,
            "scriptPubKey": {
                "asm": "",
                "type": "nonstandard"
            }
        },
        {
            "value": 506.93,
            "n": 1,
            "scriptPubKey": {
                "asm": "0377c08de701f9e9d4a72a6d5cd753040f5bf334c13dbeccdbb2a7d3a56b964951 OP_CHECKSIG",
                "reqSigs": 1,
                "type": "pubkey",
                **"addresses": [
                    "MJnXSiLfGNFUB8wj6DGd2cvebP4Qnue543"**
                ]
            }
        },
        {
            "value": 506.94458133,
            "n": 2,
            "scriptPubKey": {
                "asm": "0377c08de701f9e9d4a72a6d5cd753040f5bf334c13dbeccdbb2a7d3a56b964951 OP_CHECKSIG",
                "reqSigs": 1,
                "type": "pubkey",
                "addresses": [
                    "MJnXSiLfGNFUB8wj6DGd2cvebP4Qnue543"
                ]
            }
        }
    ],
    "blockhash": "0dbb84b18ccbfe3de1bed487a501b4a5266d49bc320d7ad1d5165bfa6f8ec4b9",
    "confirmations": 64,
    "blocktime": 1517738144
}
我使用: 。$ TX ['确认'] 和回声:64,没关系 我需要回应一下: 地址":[" MJnXSiLfGNFUB8wj6DGd2cvebP4Qnue543" ] 我能怎么做?非常感谢!

1 个答案:

答案 0 :(得分:0)

期待您的样本

 $tx['vout'][2]['scriptPubKey']['addresses'];

我已经解决了这个问题'是:

   $tx['vout'][2]['scriptPubKey']['addresses'][0]

谢谢