一直在尝试使用 go 解析此 json 文件以获取
给定城市的最低和最高温度。
{
"data": {
"current_condition": [
{
"cloudcover": "25",
"humidity": "56",
"observation_time": "01:33 PM",
"precipMM": "0.0",
"pressure": "1016",
"temp_C": "20",
"temp_F": "68",
"visibility": "10",
"weatherCode": "116",
"weatherDesc": [
{
"value": "Partly Cloudy"
}
],
"weatherIconUrl": [
{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
}
],
"winddir16Point": "SSW",
"winddirDegree": "210",
"windspeedKmph": "7",
"windspeedMiles": "4"
}
],
"request": [
{
"query": "London, United Kingdom",
"type": "City"
}
],
"weather": [
{
"date": "2014-09-07",
"precipMM": "0.0",
"tempMaxC": "23",
"tempMaxF": "74",
"tempMinC": "10",
"tempMinF": "49",
"weatherCode": "119",
"weatherDesc": [
{
"value": "Cloudy"
}
]
}
}
已成功使用结构和解码 json 字符串。
现在我想尝试使用地图,例如map[string]interface{}
如果 u 是类型map[string]interface{}并且 json 被解析为 u,则
u["data"].(map[string]interface{})["weather"]
给出值
而u["data"].(map[string]interface{})["weather"].(map[string]interface{})["tempMinC"],
给了我一个panic: interface conversion: interface is []interface {}, not map[string]interface {}
有人可以解释发生了什么吗?
相关分类