PHP访问已解码的JSON

时间:2011-06-07 20:14:58

标签: php json

我有一个PHP脚本,可以使用以下内容将JSON字符串成功解码为PHP对象:

$decodedJSON = json_decode($responseString);

$decodedJSON打印到回复时,我得到:

stdClass Object
(
    [response] => stdClass Object
        (
            [total_rows] => 2379
            [data] => Array
                (
                    [0] => Array
                        (
                            [0] => zPKfssdfg456hwCQp6XpogfTsjc
                            [1] => 3456gg4-b7ea-4bcf1680c619
                            [2] => Title Description Here.
                            [3] => Example Address 
                            [4] => 
                            [5] => 
                            [6] => Exmaple City
                            [7] => CA
                            [8] => US
                            [9] => 95616
                            [10] => (555) 555-1212
                            [11] => 
                            [12] => Food & Beverage
                            [13] => 
                            [14] => 
                            [15] => 62.79901
                            [16] => -92.80102
                            [17] => 1
                        )

                    [1] => Array
                        (
                            [0] => zPKfl6ylrwCQp6XpogfTsjc
                            [1] => 98e9945a-b7ea-4bcf1680c619
                            [2] => Title Description Here.
                            [3] => Example Address 
                            [4] => 
                            [5] => 
                            [6] => Exmaple City
                            [7] => CA
                            [8] => US
                            [9] => 95616
                            [10] => (555) 555-1212
                            [11] => 
                            [12] => Food & Beverage
                            [13] => 
                            [14] => 
                            [15] => 62.79901
                            [16] => -92.80102
                            [17] => 1
                        )

                )

            [fields] => Array
                (
                    [0] => subject_key
                    [1] => factual_id
                    [2] => name
                    [3] => address
                    [4] => address_extended
                    [5] => po_box
                    [6] => locality
                    [7] => region
                    [8] => country
                    [9] => postcode
                    [10] => tel
                    [11] => fax
                    [12] => category
                    [13] => website
                    [14] => email
                    [15] => latitude
                    [16] => longitude
                    [17] => status
                )

            [rows] => 10
            [cache-state] => CACHED
            [big-data] => 1
            [subject_columns] => Array
                (
                    [0] => 1
                )

        )

    [version] => 2
    [status] => ok
)

我的问题是:如何访问“字段”数据?我已尝试使用$decodedJSON["fields"]以及$decodedJSON[0]["fields"]$decodedJSON[0][2]以及更多变体。

有人看到我做错了吗?

非常感谢, 布雷特

2 个答案:

答案 0 :(得分:6)

尝试使用$decodedJSON->response->fields

答案 1 :(得分:5)

你可以把它解码成一个相关的数组:
$decodedJSON = json_decode($responseString, true);
然后你可以在尝试时访问

OR:$decodedJSON->response->fields