天气预报格式

时间:2016-11-12 16:52:07

标签: c# api formatting console-application

我正在使用dark sky API进行天气应用。如何在网站上获得相同的格式。这就是格式在网站上的显示方式:Stream

当我尝试打印信息时,我得到了这个:https://darksky.net/dev/docs/forecast

这是我的打印代码:

    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;

1 个答案:

答案 0 :(得分:0)

一种好方法是将JSON反序列化为C#动态obj并通过对象获取数据

dynamic data = JsonConvert.DeserializeObject(resStr);
string summary = data.currently.summary;
string temperature = data.currently.temperature;

有关api的更多详细信息,您可以查看其文档