访问json密钥时出错

时间:2013-12-24 11:11:31

标签: php json

我有以下json数据

Merchant_stripe_response Object
(
    [_response:protected] => stdClass Object
        (
            [object] => customer
            [created] => 1387883058
            [id] => cus_3BFTkHufSbD1I9
            [livemode] => 
            [description] => Order #22
            [email] => 
            [delinquent] => 
            [metadata] => stdClass Object
                (
                )

            [subscription] => 
            [discount] =>

我正在尝试获取密钥描述中的值。我试过这个

echo $_response->description

但是我收到了一个错误。

Fatal error: Cannot access protected property Merchant_stripe_response::$_response in C:\wamp\ 

我也试过json_decode来使用echo $response['description'],但它返回了空白的json。

我做错了什么吗?如何使用此结构访问密钥?

[_response:protected]

1 个答案:

答案 0 :(得分:1)

最有可能的原因是它受到保护 - 因为你不应该直接访问它。是否有一个名为getDescription()或类似吸气剂的功能?

或者,再次 - 我不鼓励这一点,因为可能有一个原因,为什么你不能,你可以延长课程:

class Merchant_stripe_response_custom extends Merchant_stripe_response {
    public function getDescription() {
        return $this->_response->description;
    }
}

似乎没有getter(源代码here),因此您必须执行上述操作,或者只需在其源代码中将protected更改为public (或在那里添加吸气剂)。

相关问题