使用Wunderground API+;PHP

使用Wunderground API+;PHP,php,json,wunderground,Php,Json,Wunderground,我目前正在尝试使用和PHP向用户输出给定城市的降水概率(POP)。WundergroundAPI以JSON格式返回其请求。但是我现在什么也没有得到,我不知道问题出在哪里 下面是我的代码: <?php $json_string = file_get_contents("http://api.wunderground.com/api/API_KEY/forecast/q/IA/Cedar_Rapids.json"); $parsed_json = json_decode($json_

我目前正在尝试使用和
PHP
向用户输出给定城市的降水概率(POP)。WundergroundAPI以JSON格式返回其请求。但是我现在什么也没有得到,我不知道问题出在哪里

下面是我的代码:

<?php
  $json_string =  file_get_contents("http://api.wunderground.com/api/API_KEY/forecast/q/IA/Cedar_Rapids.json");
  $parsed_json = json_decode($json_string);
  $location = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday'};
  $pop = $parsed_json->{'pop'};
  echo "Percipation: ${pop}%";
?>
编辑2:

下面是JSON返回(自己准备)


我认为您在中使用了错误的变量

$pop = $parsed_json->{'pop'};
试一下

$pop = $location[0]->{'pop'};

请注意,
$location
应该是一个数组,因此尝试直接访问它(
$location->{'pop'}
)将无效。
0
索引仅作为示例。

请添加来自服务器的响应,包括HTTP头。请查看此处以获取帮助。@0x笑话-它已添加。。。你想看看吗?谢谢。您能否将
$json_string
的内容添加到您的问题中?您似乎确实恢复了1270字节的内容。你有例外吗?
$pop = $parsed_json->{'pop'};
$pop = $location[0]->{'pop'};