使用以下命令获取JSON文件的内容
file_get_contents():
$str = file_get_contents('http://example.com/example.json/');现在使用解码JSON
json_depre():
$json = json_depre($str, true); // depre the JSON into an associative array
您有一个包含所有信息的关联数组。要弄清楚如何访问所需的值,可以执行以下操作:
echo '<pre>' . print_r($json, true) . '</pre>';
这将以一种易于阅读的格式打印出数组的内容。请注意,第二个参数设置为
true,以便
print_r()知道应该 返回 ed
输出(而不是仅打印到屏幕上)。然后,您可以访问所需的元素,如下所示:
$temperatureMin = $json['daily']['data'][0]['temperatureMin'];$temperatureMax = $json['daily']['data'][0]['temperatureMax'];
或根据需要遍历数组:
foreach ($json['daily']['data'] as $field => $value) { // Use $field and $value here}


