我使用黑暗天空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;发布于 2016-11-12 18:08:06
一个好方法是将JSON反序列化为C#动态obj并通过对象获取数据
dynamic data = JsonConvert.DeserializeObject(resStr);
string summary = data.currently.summary;
string temperature = data.currently.temperature;有关api的更多详细信息,请参阅其文档。
https://stackoverflow.com/questions/40565246
复制相似问题