我正在尝试解析来自此链接{J <3}}
的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;
?>
真的很感激任何帮助。感谢...
答案 0 :(得分:4)
在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;