简体   繁体   English

如何在php中读取json数据索引对象

[英]how to read json data indexed object in php

Three simple lines of code:简单的三行代码:

$input = @file_get_contents("php://input");
$event_json = json_decode($input,true);
print_r($event_json);

I have used first 2 lines to convert json data into array in php, and third line prints the following array (a portion I show here):我使用前 2 行将 json 数据转换为 php 中的数组,第三行打印以下数组(我在此处显示的部分):

Array
(
    [created] => 1326853478
    [livemode] => 
    [id] => evt_00000000000000
    [type] => charge.succeeded
    [object] => event
    [request] => 
    [pending_webhooks] => 1
    [api_version] => 2014-07-26
    [data] => Array
    (
        [object] => Array
        (
            [id] => ch_00000000000000
            [object] => charge
            [amount] => 100
            [amount_refunded] => 0

My question is: How do I echo amount (which is 100) or amount_refunded (which is 0)?我的问题是:我如何回显金额(即 100)或 amount_refunded(即 0)?

echo $event_json['data']['object']['amount'];
echo $event_json['data']['object']['amount_refunded'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM