JSON 响应中的未定义属性
Undefined property on JSON response
我正在尝试解析来自此 link api.worldweather.com
的 JSON 对象
这是我的 php 代码:
<?php
$base_url = "http://api.worldweatheronline.com/free/v2/weather.ashx?key=3be20163414371b55549cb84e2e47&q=" . "durgapur+wb&format=json";
$ret = file_get_contents($base_url);
$data = json_decode($ret);
$type = $data->data->current_condition->FeelsLikeC;
echo $type;
?>
任何帮助都将不胜感激。谢谢...
current_condition
下还有一个维度(数组):
stdClass Object
(
[data] => stdClass Object
(
[current_condition] => Array
( // index 0, this is an array
[0] => stdClass Object
(
[cloudcover] => 34
[FeelsLikeC] => 28
所以你需要一个索引 0:
$base_url = "http://api.worldweatheronline.com/free/v2/weather.ashx?key=3be20163414371b55549cb84e2e47&q=" . "durgapur+wb&format=json";
$data = json_decode(file_get_contents($base_url));
$type = $data->data->current_condition[0]->FeelsLikeC;
// ^ another nesting
echo $type;
我正在尝试解析来自此 link api.worldweather.com
的 JSON 对象这是我的 php 代码:
<?php
$base_url = "http://api.worldweatheronline.com/free/v2/weather.ashx?key=3be20163414371b55549cb84e2e47&q=" . "durgapur+wb&format=json";
$ret = file_get_contents($base_url);
$data = json_decode($ret);
$type = $data->data->current_condition->FeelsLikeC;
echo $type;
?>
任何帮助都将不胜感激。谢谢...
current_condition
下还有一个维度(数组):
stdClass Object
(
[data] => stdClass Object
(
[current_condition] => Array
( // index 0, this is an array
[0] => stdClass Object
(
[cloudcover] => 34
[FeelsLikeC] => 28
所以你需要一个索引 0:
$base_url = "http://api.worldweatheronline.com/free/v2/weather.ashx?key=3be20163414371b55549cb84e2e47&q=" . "durgapur+wb&format=json";
$data = json_decode(file_get_contents($base_url));
$type = $data->data->current_condition[0]->FeelsLikeC;
// ^ another nesting
echo $type;