【发布时间】:2019-01-23 19:44:48
【问题描述】:
好的,我有这个确实可以尝试获取天气数据 - 这会返回该字典的字符串版本:
Loaded following XML {"coord":{"lon":-118.24,"lat":34.05},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":290.19,"pressure":1027,"humidity":17,"temp_min":288.15,"temp_max":292.55},"visibility":16093,"wind":{"speed":1.27,"deg":20.0024},"clouds":{"all":1},"dt":1548269880,"sys":{"type":1,"id":3694,"message":0.0038,"country":"US","sunrise":1548255306,"sunset":1548292515},"id":5368361,"name":"Los Angeles","cod":200}
代码:
string url = "http://api.openweathermap.org/data/2.5/weather?lat=34.05&lon=-118.24&APPID=33710eba6d9c76286241d779ac1a6d9c";
WWW www = new WWW(url);
yield return www;
if (www.error == null)
{
Debug.Log("Loaded following XML " + www.text);
我想获得“天气”下的描述,但不知道如何。选择单个节点不起作用:
print(xmlDoc.SelectSingleNode("cities/list/item/weather/description/@value").InnerText);
我可以在这里做什么?
【问题讨论】:
-
JSON 不是 XML。请参阅this answer 至 How can I parse JSON with C#?
标签: c# json dictionary unity3d