2016-11-12 66 views
0

我为我的天气应用程序使用了黑暗的天空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; 
+0

看来您已经将数据外包给了解您的问题。请记住在问题本身**中提供所有必要的数据(代码,配置数据,例外名称......)。如果链接死亡或改变你的问题将失去大部分,如果不是全部的话! –

+0

在网站上重新格式化为人类可读,在代码中使用时应该没有关系。如果你想使它看起来很漂亮无论如何看到[在C#中的JSON格式?](http://stackoverflow.com/questions/4580397/json-formatter-in-c) –

回答

0

一个好方法是反序列化JSON成C#动态OBJ并通过对象

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

获取数据作进一步详细了解API,你可以看到它的文档

+0

这帮了我很多,谢谢。 –