Json 转 Map

    xiaoxiao2025-04-05  22

    public static HashMap<String, String> toHashMap(JSONObject jsonObject) { HashMap<String, String> data = new HashMap<String, String>(); Iterator it = jsonObject.keys(); // 遍历jsonObject数据,添加到Map对象 while (it.hasNext()) { String key = String.valueOf(it.next()); String value = null; try { value = (String) jsonObject.get(key); }catch (Exception e){ e.printStackTrace(); } data.put(key, value); } return data; } public static HashMap<String, MyBean> toHashMapLove(Context context,JSONObject jsonObject) { HashMap<String, MyBean> data = new HashMap<String, MyBean>(); Iterator it = jsonObject.keys(); // 遍历jsonObject数据,添加到Map对象 while (it.hasNext()) { String key = String.valueOf(it.next()); MyBean value = null; try { value = parseBean(context, jsonObject.getJSONObject(key)); }catch (Exception e){ e.printStackTrace(); } data.put(key, value); } return data; } public static LoveUser parseBean(Context context, JSONObject jsonObject) { MyBean bean=new MyBean (); bean.setUserId(getSaveString(jsonObject, "userId")); bean.setPlatform(getSaveString(jsonObject, "platform"));retrun bean; }
    转载请注明原文地址: https://ju.6miu.com/read-1297738.html
    最新回复(0)