天气预报格式
Weather forecast formatting
我正在为我的天气应用程序使用黑暗天空 API。我怎样才能获得与网站上相同的格式。这是格式在网站上的样子:https://darksky.net/dev/docs/forecast
当我尝试打印信息时,我得到了这个:https://www.scribd.com/document/330855135/ex
这是我的打印代码:
Console.Write("Please enter the name of the location: ");
string locationName = Console.ReadLine();
var location = new GoogleLocationService();
var point = location.GetLatLongFromAddress(locationName);
var lat = point.Latitude;
var lng = point.Longitude;
using (var client = new WebClient())
{
var resStr = client.DownloadString("https://api.darksky.net/forecast/d9b0a7d6636dad5856be677f4c19e4f2/" + lat + "," + lng);
output = resStr;
}
return output;
一个好的方法是将JSON反序列化为C#动态obj,通过对象
获取数据
dynamic data = JsonConvert.DeserializeObject(resStr);
string summary = data.currently.summary;
string temperature = data.currently.temperature;
有关 api 的更多详细信息,您可以查看其文档
我正在为我的天气应用程序使用黑暗天空 API。我怎样才能获得与网站上相同的格式。这是格式在网站上的样子:https://darksky.net/dev/docs/forecast
当我尝试打印信息时,我得到了这个:https://www.scribd.com/document/330855135/ex
这是我的打印代码:
Console.Write("Please enter the name of the location: ");
string locationName = Console.ReadLine();
var location = new GoogleLocationService();
var point = location.GetLatLongFromAddress(locationName);
var lat = point.Latitude;
var lng = point.Longitude;
using (var client = new WebClient())
{
var resStr = client.DownloadString("https://api.darksky.net/forecast/d9b0a7d6636dad5856be677f4c19e4f2/" + lat + "," + lng);
output = resStr;
}
return output;
一个好的方法是将JSON反序列化为C#动态obj,通过对象
获取数据dynamic data = JsonConvert.DeserializeObject(resStr);
string summary = data.currently.summary;
string temperature = data.currently.temperature;
有关 api 的更多详细信息,您可以查看其文档