如何解决如何将特定的json数据合并到一个txt文件中
<?php
$weatherdata = file_get_contents('http://api.openweathermap.org/data/2.5/weather?id=appkey');
file_put_contents('weatherdata.json',$weatherdata);
$decoded = json_decode($weatherdata);
file_put_contents('weatherdata_alert.txt',$decoded->weather[0]->description);
?>
我可以将json数据中的描述转换为标题为“ weatherdata_alert.txt”的文本,但似乎无法包含字符串中的其他数据。 这是预期的结果“晴空2°米尔布鲁克” 描述为“晴空”
这是json数据
{
"coord": {
"lon": -78.45,"lat": 44.15
},"weather": [{
"id": 804,"main": "Clouds","description": "overcast clouds","icon": "04n"
}],"base": "stations","main": {
"temp": 272.97,"feels_like": 269.29,"temp_min": 272.04,"temp_max": 274.15,"pressure": 1021,"humidity": 69
},"visibility": 10000,"wind": {
"speed": 1.5,"deg": 130
},"clouds": {
"all": 90
},"dt": 1604459237,"sys": {
"type": 1,"id": 882,"country": "CA","sunrise": 1604404430,"sunset": 1604440849
},"timezone": -18000,"id": 7804010,"name": "Millbrook","cod": 200
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。