【发布时间】:2021-11-24 13:31:32
【问题描述】:
我是 Kotlin 初学者,正在尝试创建代码以从 JSON 中获取数据。
我想从“forecastMaxtemp”中的“value”获取数据。
这是我的代码。我尝试如下但不成功。
...
Response.Listener { response ->
temp.text =
response.getJSONArray (name"weatherForecast").
getJSONObject(0).
getJSONObject("forecastMaxtemp").
getString(name"value")
},
JSON 数据
{"generalSituation":No Alarm",
"weatherForecast":[{
"forecastDate":"20211004",
"week":"Monday",
"forecastWind":"East force 4 to 5.",
"forecastWeather":"Sunny periods.",
"forecastMaxtemp":{"value":31,"unit":"C"},
"forecastMintemp":{"value":27,"unit":"C"},
...
...
]
}
【问题讨论】:
-
感谢您的建议我该如何修改它如果我想在一个 JSONObject 中获取两个值(“值”和“单位”)