简体   繁体   English

JSON PHP 解码

[英]JSON PHP Decode

i have an extern JSON File and no problems to get Airline, Price, etc.. But how can i get [ACE] ?我有一个外部 JSON 文件,获取航空公司、价格等没有问题。但是我怎样才能获取 [ACE] 呢?

[success] => 1
[data] => Array
    (
        [ACE] => Array
            (
                [0] => Array
                    (
                        [price] => 477
                        [airline] => AB
                        [flight_number] => 2434
                        [departure_at] => 2014-08-09T12:30:00Z
                        [return_at] => 2014-08-24T08:35:00Z
                        [expires_at] => 2014-04-03T22:46:17Z
                    )

            )

$foo = $json['data']['ACE']; should do it.应该这样做。

Unless you want to get the key from the $data array, in which case:除非您想从$data数组中获取密钥,在这种情况下:

foreach ($json['data'] as $k=>$v) {
    $foo = $k; // this is 'ACE'.
    break;
}

Edited as per comment.根据评论编辑。

['ACE'] is an array? ['ACE'] 是一个数组?

Your getting the data from it starting with the first - [0]您从第一个开始获取数据 - [0]

Then the ['price'] of the first one?那么第一个的['价格']?

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

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