0
am have difficulty reading this json, because it has, in some returns, multiple addresses, image example below:
Finally, can anyone help me? , I need to load or the Addressmain, highlighted in the image above.
Paths: Object->Result->0->Creditdata->0->Addresses->0->Addressmain Object->Result->0->Creditdata->0->Addresses->1->Addressmain
How I set up my code:
<?php
$json_data = json_decode(file_get_contents('arquivo2.json'));
foreach ($json_data->Result-> as $data) {
echo '<br>País: ' .$data->CreditData-> ->Addresses-> ->Country;
echo '<br>';
}
?>
My mistake is in the "way" the "0", "1" are breaking me... if anyone can give me a hint I thank
Paul, I tried but it didn’t work ... gave error
– Marcos RS
What error returned? It can provide json as well?
– Paulo Victor
Return this error: Warning: Invalid argument supplied for foreach() in C: Docker www index3.php on line 5 Call Stack # Time Memory Function Location 1 0.0030 361968 {main}( ) ... index3.php:0
– Marcos RS
Since json_decode is not returning an array, you have added the true parameter?
– Paulo Victor
yes ... parameter this true
– Marcos RS
You can provide json for me to check the error?
– Paulo Victor
Paulo, I got ... the error was result and has to be Result... but I follow with a problem still it continues loading only one of the address, it does not load the second form "automatically"...
– Marcos RS
@Paulovictor is missing a second loop inside the foreach to grab the values of the keys .....................
[0]["Country"]
...[1]["Country"]
.. and so on.– Andrei Coelho
As I said, he has the option to use the first input or make another loop, I gave only one example.
– Paulo Victor
Paulo Victor has how to contact you?
– Marcos RS