JSONObject转换成Map对象
String result = sendRequest(jsonObject.toString(), 2L, url);  //json字符串
JSONObject res = JSONObject.fromObject(result);
if ("true".equals(res.getString("status"))) {
   JSONObject data = res.getJSONObject("data");
   Iterator it = data.keys();
   // 遍历jsonObject数据,添加到Map对象
   while (it.hasNext()){
//通过key获取value String key = String.valueOf(it.next()); Double value = data.getDouble(key); map.put(key, value); } }
//第二种  效率更高,key和value同时获取,适用于大数据量
Iterator it =data.entrySet().iterator();
while (it.hasNext()) {
   Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
   map.put(entry.getKey(), entry.getValue());
}

  

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-08-26
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-08
  • 2022-01-13
  • 2021-08-03
  • 2021-05-10
  • 2022-12-23
  • 2021-10-03
相关资源
相似解决方案