首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >天气预报格式

天气预报格式
EN

Stack Overflow用户
提问于 2016-11-12 16:52:07
回答 1查看 980关注 0票数 0

我使用黑暗天空API作为我的天气应用程序。如何获得相同的格式,就像在网站上一样。这是格式化在网站上的样子:https://darksky.net/dev/docs/forecast

当我试图打印信息时,我得到了这样的信息:https://www.scribd.com/document/330855135/ex

这是我的打印代码:

代码语言:javascript
复制
    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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-12 18:08:06

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

代码语言:javascript
复制
dynamic data = JsonConvert.DeserializeObject(resStr);
string summary = data.currently.summary;
string temperature = data.currently.temperature;

有关api的更多详细信息,请参阅其文档。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40565246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档