Here is my php code with json formatted string:
$string=';
?>
I want to learn how to parse/output json string into something I can show in html or put into database .. however i am stuck on something that is prob very simple but I've spent most of the morning trying to figure out.
What I want to understand is why the results of my code above gives me the following result:
"items: Array"
And not what I want/expect to get:
"items: W 7th Ave"
"items: W 8th St"
What am i missing? Isn't "Address" the next "level" down from "Item" in the array?
盾畳圭宛
$string=file_get_contents('https://www.it1352.com/string.json');
$json=json_decode($string);
if you want to have items:
:
foreach ($json['items'] as $address)
{
echo "items:". $address['address'] ."
";
};
anyway if you are not sure about how an array is built you could print it via:
print_r($json);
which will print:
Array
(
[items]=> Array
(
[0]=> Array
(
[address]=> W 7th Ave
)
[1]=> Array
(
[address]=> W 8th St
)
)
)
now you found out that $json contains just an array (items) of two array, then, if you loop it, you will get that array which is printed in your example.
As explained above you need to go one step deeper by looping the elements in your items array and print their address element.
here is the complete script: http://pastie.org/2275879
标签:string,items,decode,json,address,array,php,Array From: https://blog.51cto.com/yetaotao/5800292