我使用下面的代码调用了一项网络服务。现在我想从它中呼应一些价值。但我不能。我尝试了一些选项,但没有奏效。
<?php
$api_url = "myurl";
$response = file_get_contents($api_url);
$my_array = json_decode($response, true);
?>
上面的代码给了我 JSON 共鸣
{
"places":{
"place":[
{
"place_id":"FHa5VXVTU7MbX9qW",
"woeid":"2192348",
"latitude":"32.433",
"longitude":"74.366",
"place_url":"\/Pakistan\/Punjab\/Bhopalwala",
"place_type":"locality",
"place_type_id":"7",
"timezone":"Asia\/Karachi",
"name":"Bhopalwala, Punjab, Pakistan",
"woe_name":"Bhopalwala"
}
],
"latitude":"32.45",
"longitude":"74.34",
"accuracy":"16",
"total":1
},
"stat":"ok"
}
我试图回应 woe_name。
echo $my_array['places']['place']['woe_name'];
print $my_array->places["0"]->place->woe_name;
这是 var_dump
array(2) {
["places"]=>
array(5) {
["place"]=>
array(1) {
[0]=>
array(10) {
["place_id"]=>
string(16) "FHa5VXVTU7MbX9qW"
["woeid"]=>
string(7) "2192348"
["latitude"]=>
string(6) "32.433"
["longitude"]=>
string(6) "74.366"
["place_url"]=>
string(27) "/Pakistan/Punjab/Bhopalwala"
["place_type"]=>
string(8) "locality"
["place_type_id"]=>
string(1) "7"
["timezone"]=>
string(12) "Asia/Karachi"
["name"]=>
string(28) "Bhopalwala, Punjab, Pakistan"
["woe_name"]=>
string(10) "Bhopalwala"
}
}
["latitude"]=>
string(5) "32.45"
["longitude"]=>
string(5) "74.34"
["accuracy"]=>
string(2) "16"
["total"]=>
int(1)
}
["stat"]=>
string(2) "ok"
}
我该怎么做?