我从Api那里得到了这样的回应。其中locationSector是固定密钥,但内部密钥可以存在或不存在,也可以与密钥值相对应。这是json字符串。我如何将其存储在hashmap中,内部值也可以存储在hash map中,如。HashMap<String, HashMap<String,List<String>>>
"locationSector": {
"Adampur": [
"Adampur",
"Agroha",
"Anaj Mandi",
"Auto Market",
"Bhadu Colony",
"Chulibagrian"
],
"Allahabad": [
"Allahabad"
],
"Gurgaon":[
"Dlf 1",
"Dlf 2"
]
}发布于 2019-10-03 21:41:58
如果您使用的是org.json库,请尝试以下内容:
import com.fasterxml.jackson.databind.ObjectMapper;
Map<String, Object> response = new ObjectMapper().readValue(str, HashMap.class);str = youre是json字符串。
就这么简单,如果你想要一个studentId,
String studentIds = response.get("student id").toString();https://stackoverflow.com/questions/58220065
复制相似问题