我正在尝试使用在网站上找到的代码通过Openweathermap API来获取天气预报,但没有得到任何输出。这是函数的内容:
$city="Rivanazzano";
$country="IT";
$url="http://api.openweathermap.org/data/2.5/forecast/daily?q=".$city.",".$country."&units=metric&cnt=7&lang=it&appid=MY_API_KEY";
$json=file_get_contents($url);
$data=json_decode($json,true);
$HTML ="<p>";
foreach($data['list'] as $day => $value) {
$HTML .="Max temperature for day " . $day . " will be " . $value['temp']['max'] . "<br />" ;
}
$HTML .="</p>";
return $HTML;
但是正如我所说的,我无法获取数据,我认为问题在于API返回给我的JSON的结构与讨论中报告的结构不同。 JSON是这样的:
Array
[city] => Array
(
[id] => 3169258
[name] => Rivanazzano
[coord] => Array
(
[lon] => 9.0142
[lat] => 44.9308
)
[country] => IT
[population] => 4429
)
[cod] => 200
[message] => 1.5395815
[cnt] => 7
[list] => Array
(
[0] => Array
(
[dt] => 1550401200
[temp] => Array
(
[day] => 9.69
[min] => -1.23
[max] => 9.69
[night] => -1.23
[eve] => 3.5
[morn] => 9.69
)
[pressure] => 1015.56
[humidity] => 71
[weather] => Array
(
[0] => Array
(
[id] => 800
[main] => Clear
[description] => cielo sereno
[icon] => 01d
)
)
[speed] => 1.38
[deg] => 320
[clouds] => 0
)
[1] => Array
(
[dt] => 1550487600
[temp] => Array
(
[day] => 10.84
[min] => -1.13
[max] => 12.03
[night] => -0.04
[eve] => 5.93
[morn] => -1.13
)
[pressure] => 1014.43
[humidity] => 89
[weather] => Array
(
[0] => Array
(
[id] => 800
[main] => Clear
[description] => cielo sereno
[icon] => 01d
)
)
[speed] => 1.62
[deg] => 268
[clouds] => 0
)
[2] => Array
(
[dt] => 1550574000
[temp] => Array
(
[day] => 10.63
[min] => -1.57
[max] => 11.46
[night] => 2.31
[eve] => 6.16
[morn] => -1.57
)
[pressure] => 1012.78
[humidity] => 88
[weather] => Array
(
[0] => Array
(
[id] => 800
[main] => Clear
[description] => cielo sereno
[icon] => 01d
)
)
[speed] => 1.81
[deg] => 279
[clouds] => 0
)
[3] => Array
(
[dt] => 1550660400
[temp] => Array
(
[day] => 9.83
[min] => 0.13
[max] => 10.78
[night] => 0.5
[eve] => 5.54
[morn] => 0.13
)
[pressure] => 1014.53
[humidity] => 93
[weather] => Array
(
[0] => Array
(
[id] => 500
[main] => Rain
[description] => pioggia leggera
[icon] => 10d
)
)
[speed] => 1.92
[deg] => 347
[clouds] => 8
)
[4] => Array
(
[dt] => 1550746800
[temp] => Array
(
[day] => 9.9
[min] => 5.78
[max] => 9.9
[night] => 6.69
[eve] => 8.44
[morn] => 5.78
)
[pressure] => 1014.1
[humidity] => 0
[weather] => Array
(
[0] => Array
(
[id] => 500
[main] => Rain
[description] => pioggia leggera
[icon] => 10d
)
)
[speed] => 1.83
[deg] => 349
[clouds] => 29
[rain] => 1.1
)
[5] => Array
(
[dt] => 1550833200
[temp] => Array
(
[day] => 8.59
[min] => 3.21
[max] => 8.59
[night] => 3.21
[eve] => 6.54
[morn] => 5.17
)
[pressure] => 1016.34
[humidity] => 0
[weather] => Array
(
[0] => Array
(
[id] => 500
[main] => Rain
[description] => pioggia leggera
[icon] => 10d
)
)
[speed] => 6.51
[deg] => 81
[clouds] => 84
)
[6] => Array
(
[dt] => 1550919600
[temp] => Array
(
[day] => 6.75
[min] => 1.46
[max] => 6.75
[night] => 1.46
[eve] => 4.99
[morn] => 2.09
)
[pressure] => 1019.49
[humidity] => 0
[weather] => Array
(
[0] => Array
(
[id] => 500
[main] => Rain
[description] => pioggia leggera
[icon] => 10d
)
)
[speed] => 3.98
[deg] => 54
[clouds] => 19
[rain] => 1.14
)
)
有人可以帮我吗?
答案 0 :(得分:0)
好吧,看起来好像返回了一个php数组,因此,如果您要删除json_decode函数(因为它不是json但已经是一个php数组),您应该能够获得像$ result ['cod']这样的数据并获得200背部。希望这会有所帮助
答案 1 :(得分:0)
尝试一下。希望对您有所帮助。
import multiprocessing as mp
import numpy as np
def test():
def worker(i):
return i + 1
task = np.linspace(1, 10, 10)
pool = mp.Pool(3)
result = list(pool.map(worker, task))
return result
print(test())