Posts

Showing posts with the label Map

Convert JSONObject To Map

Answer : use Jackson (https://github.com/FasterXML/jackson) from http://json.org/ HashMap<String,Object> result = new ObjectMapper().readValue(<JSON_OBJECT>, HashMap.class); You can use Gson() (com.google.gson) library if you find any difficulty using Jackson. HashMap<String, Object> yourHashMap = new Gson().fromJson(yourJsonObject.toString(), HashMap.class); This is what worked for me: public static Map<String, Object> toMap(JSONObject jsonobj) throws JSONException { Map<String, Object> map = new HashMap<String, Object>(); Iterator<String> keys = jsonobj.keys(); while(keys.hasNext()) { String key = keys.next(); Object value = jsonobj.get(key); if (value instanceof JSONArray) { value = toList((JSONArray) value); } else if (value instanceof JSONObject) { value = toMap((JSONObject) value); } map.put(key,...