[英]How to parse a JSON map in Java or Kotlin where the map has a key
I'm sending a Map from a server to a Android app as a JSON file.我将 Map 作为 JSON 文件从服务器发送到 Android 应用程序。 Previously I was sending Arrays, Strings, Booleans, and Longs which were decoded by null checks and
以前我发送的是 Arrays、字符串、布尔值和长整数,它们由 null 检查和解码
json.getJSONArray(key)
or similar, where json is a JSONObject and key is a String.或类似的,其中 json 是 JSONObject 而 key 是字符串。
.getJSONMap(key)
does not exist and other similar questions do not provide answers that include the case where the JSON has other data and needs a key to specify where the map is. .getJSONMap(key)
不存在且其他类似问题不提供答案,包括 JSON 具有其他数据并且需要密钥来指定 map 所在位置的情况。
What can I use to parse the JSON to a map given a key?在给定密钥的情况下,我可以使用什么将 JSON 解析为 map?
You want json.getJSONObject(key)
你想要
json.getJSONObject(key)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.