json转换成list map集合

时间:2025-03-21 21:23:23
import ; import ; import ; import ; import ; import ; public class JSONHelper { /** * 将JSONObjec对象转换成Map集合 * @see JSONHelper#reflect(JSONArray) * @param json * @return */ public static HashMap<String, Object> reflect(JSONObject json){ HashMap<String, Object> map = new HashMap<String, Object>(); Set keys = (); for(Object key : keys){ Object o = (key); if(o instanceof JSONArray) ((String) key, reflect((JSONArray) o)); else if(o instanceof JSONObject) ((String) key, reflect((JSONObject) o)); else ((String) key, o); } return map; } /** * 将JSONArray对象转换成List集合 * @see JSONHelper#reflect(JSONObject) * @param json * @return */ public static Object reflect(JSONArray json){ List<Object> list = new ArrayList<Object>(); for(Object o : json){ if(o instanceof JSONArray) (reflect((JSONArray) o)); else if(o instanceof JSONObject) (reflect((JSONObject) o)); else (o); } return list; } }