我从 Api 收到了这样的响应。其中locationSector是固定key,但内部key可能存在也可能不存在,并且也对应key值。
这是 json 字符串。
我如何将其存储在 HashMap 中,内部值也可以存储在 HashMap 中。
HashMap<String, HashMap<String,List<String>>>
"locationSector": {
"Adampur": [
"Adampur",
"Agroha",
"Anaj Mandi",
"Auto Market",
"Bhadu Colony",
"Chulibagrian"
],
"Allahabad": [
"Allahabad"
],
"Gurgaon":[
"Dlf 1",
"Dlf 2"
]
}
最佳答案
如果您使用 org.json 库,请尝试一下:
import com.fasterxml.jackson.databind.ObjectMapper;
Map<String, Object> response = new ObjectMapper().readValue(str, HashMap.class);
str = 你是 json 字符串。
就这么简单,如果你想要一个studentId,
String studentIds = response.get("student id").toString();
关于java - android 中如何处理这种类型的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58220065/