使用 php/jquery/html 标记 Yahoo Weather (JSON)
Marking up Yahoo Weather (JSON) using php/jquery/html
我使用 YQL 查询 return 来自 Yahoo Weather 的 JSON 对象。但是我不确定如何标记这个对象。
returning JSON 对象是:
{
"query":{
"count":3,
"created":"2017-12-01T20:28:57Z",
"lang":"en-GB",
"results":{
"channel":[
{
"item":{
"forecast":{
"code":"28",
"date":"01 Dec 2017",
"day":"Fri",
"high":"3",
"low":"0",
"text":"Mostly Cloudy"
}
}
},
{
"item":{
"forecast":{
"code":"26",
"date":"02 Dec 2017",
"day":"Sat",
"high":"7",
"low":"1",
"text":"Cloudy"
}
}
},
{
"item":{
"forecast":{
"code":"26",
"date":"03 Dec 2017",
"day":"Sun",
"high":"8",
"low":"6",
"text":"Cloudy"
}
}
}
]
}
}
}
我可以看到层次结构是:
查询 > 结果 > 频道[项目 > 预报 > 天气数据]
感谢任何帮助或指向网页/文档的指示。如果需要,我也很乐意提供任何进一步的信息。
谢谢
您可以使用json_decode
轻松解析JSON:
<?php
$json = file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20title%2C%20units.temperature%2C%20item.forecast%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places%20where%20text%3D%22Stoke%20On%20Trent%2C%20United%20Kindgdom%22)%20and%20u%20%3D%20%22C%22%20limit%203%20%7C%20sort(field%3D%22item.forecast.date%22%2C%20descending%3D%22false%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
$data = json_decode($json);
echo $data->query->count; // Will echo out the value of count, 3 in this case
我使用 YQL 查询 return 来自 Yahoo Weather 的 JSON 对象。但是我不确定如何标记这个对象。
returning JSON 对象是:
{
"query":{
"count":3,
"created":"2017-12-01T20:28:57Z",
"lang":"en-GB",
"results":{
"channel":[
{
"item":{
"forecast":{
"code":"28",
"date":"01 Dec 2017",
"day":"Fri",
"high":"3",
"low":"0",
"text":"Mostly Cloudy"
}
}
},
{
"item":{
"forecast":{
"code":"26",
"date":"02 Dec 2017",
"day":"Sat",
"high":"7",
"low":"1",
"text":"Cloudy"
}
}
},
{
"item":{
"forecast":{
"code":"26",
"date":"03 Dec 2017",
"day":"Sun",
"high":"8",
"low":"6",
"text":"Cloudy"
}
}
}
]
}
}
}
我可以看到层次结构是: 查询 > 结果 > 频道[项目 > 预报 > 天气数据]
感谢任何帮助或指向网页/文档的指示。如果需要,我也很乐意提供任何进一步的信息。
谢谢
您可以使用json_decode
轻松解析JSON:
<?php
$json = file_get_contents("https://query.yahooapis.com/v1/public/yql?q=select%20title%2C%20units.temperature%2C%20item.forecast%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places%20where%20text%3D%22Stoke%20On%20Trent%2C%20United%20Kindgdom%22)%20and%20u%20%3D%20%22C%22%20limit%203%20%7C%20sort(field%3D%22item.forecast.date%22%2C%20descending%3D%22false%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
$data = json_decode($json);
echo $data->query->count; // Will echo out the value of count, 3 in this case