I am reading a file json
external (Through a URL
) and I can get the values of the first content without problem, but the second content does not, I imagine that the problem is due to the brackets "[ ] "at the beginning and end.
Any suggestions to solve it? there is some other way to get 2 or more values without repeating the code echo:
,
Example :
echo "Data: ". $json_data{"last_name"}
and
echo "Data: ". $json_data{"age"}
Content url_01:
{
"name": Karl,
"last_name": Smith,
"age": 35
}
$url = "url_01";
$json = file_get_contents($url);
$json_data = json_decode($json, true);
echo "Data: ". $json_data{"name"}
It works well!
Content url_02:
[
{
"name": Karl,
"last_name": Smith,
"age": 35
}
]
$url = "url_02";
$json = file_get_contents($url);
$json_data = json_decode($json, true);
echo "Data: ". $json_data{"name"}];
It does not work well!