Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP从多层JSON数组中获取值_Php_Arrays_Json - Fatal编程技术网

PHP从多层JSON数组中获取值

PHP从多层JSON数组中获取值,php,arrays,json,Php,Arrays,Json,我似乎在使用JSON数组时遇到了一些问题。我想知道是否有人能帮助我 我有下面的JSON数组,我想得到发票号中的数字 $json = ' { "id": "PAY-7MP775806F4135612LLCHE4I", "intent": "sale", "state": "approved", "cart": "9KA22662P3559221J", "payer": { "payment_method": "paypal",

我似乎在使用JSON数组时遇到了一些问题。我想知道是否有人能帮助我

我有下面的JSON数组,我想得到发票号中的数字

$json = '
{
    "id": "PAY-7MP775806F4135612LLCHE4I",
    "intent": "sale",
    "state": "approved",
    "cart": "9KA22662P3559221J",
    "payer": 
    {
        "payment_method": "paypal",
        "status": "VERIFIED",
        "payer_info": 
        {
            "email": "accounts-buyer@traxprint.com",
            "first_name": "test",
            "last_name": "buyer",
            "payer_id": "ZR6SRXGS252RG",
            "shipping_address": 
            {
                "recipient_name": "test buyer",
                "line1": "1 Cheeseman Ave Brighton East",
                "city": "Melbourne",
                "state": "Victoria",
                "postal_code": "3001",
                "country_code": "AU"
            },
            "phone": "0364424947",
            "country_code": "AU"
        }
    },
    "transactions": 
    [
        {
            "amount": 
            {
                "total": "3.00",
                "currency": "USD",
                "details": 
                {
                    "subtotal": "3.00"
                }
            },
            "payee": 
            {
                "merchant_id": "DSTEYCMCDUL3Y"
            },
            "description": "Payment description",
            "invoice_number": "abc1231522823790",
            "item_list": 
            {
                "items": 
                [
                    {
                        "name": "Subscribe",
                        "sku": "sub1",
                        "price": "3.00",
                        "currency": "USD",
                        "tax": "0.00",
                        "quantity": 1
                    }
                ],
                "shipping_address": 
                {
                    "recipient_name": "test buyer",
                    "line1": "1 Cheeseman Ave Brighton East",
                    "city": "Melbourne",
                    "state": "Victoria",
                    "postal_code": "3001",
                    "country_code": "AU"
                }
            },
            "related_resources": 
            [
                {
                    "sale": 
                    {
                        "id": "41B66647LJ233225Y",
                        "state": "completed",
                        "amount": 
                        {
                            "total": "3.00",
                            "currency": "USD",
                            "details": 
                            {
                                "subtotal": "3.00"
                            }
                        },
                        "payment_mode": "INSTANT_TRANSFER",
                        "protection_eligibility": "ELIGIBLE",
                        "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
                        "transaction_fee": 
                        {
                            "value": "0.37",
                            "currency": "USD"
                        },
                        "parent_payment": "PAY-7MP775806F4135612LLCHE4I",
                        "create_time": "2018-04-04T06:36:59Z",
                        "update_time": "2018-04-04T06:36:59Z",
                        "links": 
                        [
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y",
                                "rel": "self",
                                "method": "GET"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y/refund",
                                "rel": "refund",
                                "method": "POST"
                            },
                            {
                                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
                                "rel": "parent_payment",
                                "method": "GET"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "create_time": "2018-04-04T06:36:33Z",
    "links": 
    [
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
            "rel": "self",
            "method": "GET"
        }
    ]
}';

我试图使用的代码是,但出现了错误未定义属性:stdClass::$invoice\u number

$decoded = json_decode($json);
echo $Info = $decoded->transactions[0]->payee->invoice_number;
有人能告诉我为什么这不起作用吗

谢谢

罗伯特


什么错误?请添加到问题中。未定义的属性:stdClass::$invoice\u number他们是对的,
收款人
中没有
发票号
,而是在
交易
中。你是一个传奇。Thanks@BooberBunz顺便说一句,google chrome的网络商店有一个免费离线使用的
Json编辑器:)
echo $Info = $decoded->transactions[0]->invoice_number;