【问题标题】:How to get "variable" of Response Object如何获取响应对象的“变量”
【发布时间】:2021-12-19 03:49:41
【问题描述】:

我在 PHP 中使用一个 API,当我调用一个函数时它会打印:

PagSeguro\Parsers\Transaction\CreditCard\Response Object
(
    [date:PagSeguro\Parsers\Transaction\Response:private] => 2021-11-04T21:10:12.000-03:00
    [code:PagSeguro\Parsers\Transaction\Response:private] => X
    [reference:PagSeguro\Parsers\Transaction\Response:private] => Y

[...]

我需要得到code:PagSeguro\Parsers\Transaction\Response:private 结果,但我不知道怎么做。要调用此响应,该行是: $result = $creditCard->register(\PagSeguro\Configuration\Configure::getAccountCredentials());

【问题讨论】:

标签: php arrays api object response


【解决方案1】:

这是我为使其工作而编写的代码。

try {
    //Get the crendentials and register the boleto payment
    $result = $creditCard->register(
        \PagSeguro\Configuration\Configure::getAccountCredentials()
    );
    
    $array = (array) $result; // makes it a "normal" array
    $values = array_values($array); // get all those values
    $transactionid = $values[1]; // returns the second value

【讨论】:

    猜你喜欢
    • 2016-08-08
    • 1970-01-01
    • 2021-09-13
    • 2020-01-23
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多