0

I have a json array for data in php and I am trying to echo the value "transaction id". Can you please help

SquareConnect\Model\ChargeResponse Object
(
    [errors:protected] => 
    [transaction:protected] => SquareConnect\Model\Transaction Object
        (
            [id:protected] => cx4V
            [location_id:protected] => 5TRMFA
            [created_at:protected] => 2017-12-11T01:53:22Z
            [tenders:protected] => Array
                (
                    [0] => SquareConnect\Model\Tender Object
                        (
                            [id:protected] => 001F
                            [location_id:protected] => 5TRA
                            [transaction_id:protected] => cx4x35peV
                            [created_at:protected] => 2017-12-11T01:53:22Z
                            [note:protected] => Online Transaction
                            [amount_money:protected] => SquareConnect\Model\Money Object
                                (
                                    [amount:protected] => 100
                                    [currency:protected] => USD
                                )
3

2 Answers 2

1

I cab give you technique. Please code yourself. 1. Convert JSON to ARRAY. 2. Then select value from array .

$json = '
{
    "type": "donut",
    "name": "Cake"
}';

$yummy = json_decode($json);

echo $yummy->type; //donut
Sign up to request clarification or add additional context in comments.

Comments

0

You can first convert your Json data to Array like below:

$json = json_decode( json_encode($json), true);

Then In foreach you can get your data very easily:

foreach($json as $data){
   echo $data['transaction_id'];
}

If you want to simply print your Json data without converting to array then do like below:

foreach($json as $data){
   echo $data->transaction_id;
}

And before doing anything, print your json data so that it will be more clear where transaction_id is actually located and how to fetch it.

echo "<pre>"; print_r($json); die;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.