2013-07-31 63 views
0

所以我做了这个脚本,基本上是一个命令。未定义指数天气

它所做的是,用户使用$ arg定义命令“weather”,其中$ arg就是所说的内容。然后对生成的json进行解码,然后仅从json发送包。但它说“位置”和“温度”是不确定的。

有人可以帮我解决这个问题吗?数据包得到正确发送,但数据包发送时不显示位置或温度。数据包sm =发送消息。

这里是代码

if($cmd == 'weather'){ 
$file = file_get_contents('http://weather3.pricop.info/api.php?city=' . $arg); 
$weather = json_decode($file, true); 
$user->sendPacket("%xt%sm%-1%0%" . " Temperature for " . $weather["location"] . "%" . " will be " . $weather["temperature"] . "%"); 
} 
+0

请出示'的var_dump($文件);' - 我们真的不能调试为什么你的JSON也不是没有看到JSON ;-) – DaveRandom

+0

HTTP解码权://prntscr.com/1io71v – user2524169

回答

2

的回应是这样的:

{"apiVersion":"1.0", "data":{ "location":"Pascagoula, MS", "temperature":"79", "skytext":"Mostly Cloudy", "humidity":"84", "wind":"6", "date":"2013-07-31", "day":"Wednesday" } } 

返回的数据有数据属性里面,所以你必须引用位置属性。它作为

$weather["data"]["location"]; 

$weather["data"]["temperature"]; 
+0

非常感谢!有用 :) – user2524169