O
O
oleg2018-06-21 09:41:05
PHP
oleg, 2018-06-21 09:41:05

How to get values ​​from json array?

There is an API. I get a response from him in a json array using curl_init ();
I check the answer like this:

$resp = json_decode($response, true);
print_r ($resp);

I see this:
Array ( [success] => 1 [data] => Array ( [0] => Array ( [Number] => 20400091908900 [DateCreated] => 19-06-2018 00:00:00 [DocumentWeight] = > 1.75 [CheckWeight] => 0 [DocumentCost] => 66 [SumBeforeCheckWeight] => 0 [PayerType] => Recipient [RecipientFullName] => [RecipientDateTime] => [OwnerDocumentType] => [ScheduledDeliveryDate] => 22-06- 2018 [PaymentMethod] => Cash [CargoDescriptionString] => [CargoType] => Parcel [CitySender] => Kherson [CityRecipient] => Stanytsia Lugansk [WarehouseRecipient] => Warehouse #3....I won't give the whole text ()
So, I don't understand how to extract values ​​by keys, I
tried
echo $resp->DateCreated;
or
echo $resp['DateCreated']; - with and without quotes.
As I understand it, there are still many nested arrays. Tried to parse them foreach();
But just as ineffective. To be honest, I didn’t work with json and I don’t understand how it builds an array. I've been trying for two days with no results. Help me please! Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypt3r, 2018-06-21
@donotar

foreach ($resp['data'] as $i => $row) {
    echo $row['DateCreated'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question