Read JSON return from PHP Curl

Asked

Viewed 638 times

1

Just read a certain Curl return value. By giving the $arrData =json_decode($var); where $var is the return of curl_exec

Obtenho:

    stdClass Object
    (
        [id] => PAY-A8XUTU4VSTE6
        [status] => WAITING
        [delayCapture] => 
        [amount] => stdClass Object
            (
                [total] => 120
                [fees] => 0
                [refunds] => 0
                [liquid] => 120
                [currency] => BRL
            )

        [installmentCount] => 1
        [fundingInstrument] => stdClass Object
            (
                [boleto] => stdClass Object
                    (
                        [expirationDate] => 2017-06-05
                        [lineCode] => 23793.39126 60000.105274 54001.747903 9 71810000000120
                        [instructionLines] => stdClass Object
                            (
                                [first] => Site
                            )

                    )

                [method] => BOLETO
            )

        [fees] => Array
            (
                [0] => stdClass Object
                    (
                        [type] => TRANSACTION
                        [amount] => 0
                    )

            )

        [events] => Array
            (
                [0] => stdClass Object
                    (
                        [type] => PAYMENT.CREATED
                        [createdAt] => 2017-05-26T19:25:34.913-03
                    )

                [1] => stdClass Object
                    (
                        [type] => PAYMENT.WAITING
                        [createdAt] => 2017-05-26T19:25:34.913-03
                    )

            )

        [receivers] => Array
            (
                [0] => stdClass Object
                    (
                        [moipAccount] => stdClass Object
                            (
                                [id] => MPA-**********
                                [login] => [email protected]
                                [fullname] => Fulano
                            )

                        [type] => PRIMARY
                        [amount] => stdClass Object
                            (
                                [total] => 120
                                [refunds] => 0
                            )

                    )

            )

        [_links] => stdClass Object
            (
                [self] => stdClass Object
                    (
                        [href] => https://sandbox.moip.com.br/v2/payments/PAY-A8XUTU4VSTE6
                    )

                [order] => stdClass Object
                    (
                        [href] => https://sandbox.moip.com.br/v2/orders/ORD-SLKVC9BB5OCT
                        [title] => ORD-SLKVC9BB5OCT
                    )

                [payBoleto] => stdClass Object
                    (
                        [redirectHref] => https://checkout-sandbox.moip.com.br/boleto/PAY-A8XUTU4VSTE6
                    )

            )

        [createdAt] => 2017-05-26T19:25:34.913-03
        [updatedAt] => 2017-05-26T19:25:34.913-03
    )

Now what I need exactly is to know how to capture a certain value within this, as an example that I tried:

echo $arrData["_links"][0]['payBoleto']['redirectHref'];

Call me back, Cannot use object of type stdClass as array

How exactly to fetch a value within this return?

  • 1

    Use json_decode($var, true) to return as array.

  • show buddy, added the true and did the reading with echo $arrData["_links"]['payBoleto']['redirectHref'];, return obtained. Do as response there to score you

1 answer

2

Adding the json_decode($var, true) for return as an array.

Taking the values: echo $arrData["_links"]['payBoleto']['redirectHref'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.