@Test public void testConvertJSONObjectToMap() throws JSONException { JSONObject json = new JSONObject(); json.put("Total Score", 20); JSONObject internalJSON = new JSONObject(); internalJSON.put("Innings 1", 10); internalJSON.put("Innings 2", 10); json.put("Innings Scores", internalJSON); Map<String, Object> scoreMap = (Map<String, Object>) ParseDecoder.get().decode(json); assertNotNull(scoreMap); assertEquals(2, scoreMap.size()); assertEquals(20, scoreMap.get("Total Score")); Map<String, Object> inningsMap = (Map<String, Object>) scoreMap.get("Innings Scores"); assertNotNull(inningsMap); assertEquals(2, inningsMap.size()); assertEquals(10, inningsMap.get("Innings 1")); assertEquals(10, inningsMap.get("Innings 2")); }
Map<String, Object> convertJSONObjectToMap(JSONObject object) { Map<String, Object> outputMap = new HashMap<>(); Iterator<String> it = object.keys(); while (it.hasNext()) { String key = it.next(); Object value = object.opt(key); outputMap.put(key, decode(value)); } return outputMap; }
ParseDecoder { Map<String, Object> convertJSONObjectToMap(JSONObject object) { Map<String, Object> outputMap = new HashMap<>(); Iterator<String> it = object.keys(); while (it.hasNext()) { String key = it.next(); Object value = object.opt(key); outputMap.put(key, decode(value)); } return outputMap; } }
ParseDecoder { Map<String, Object> convertJSONObjectToMap(JSONObject object) { Map<String, Object> outputMap = new HashMap<>(); Iterator<String> it = object.keys(); while (it.hasNext()) { String key = it.next(); Object value = object.opt(key); outputMap.put(key, decode(value)); } return outputMap; } protected  ParseDecoder(); }
ParseDecoder { Map<String, Object> convertJSONObjectToMap(JSONObject object) { Map<String, Object> outputMap = new HashMap<>(); Iterator<String> it = object.keys(); while (it.hasNext()) { String key = it.next(); Object value = object.opt(key); outputMap.put(key, decode(value)); } return outputMap; } protected  ParseDecoder(); static ParseDecoder get(); Object decode(Object object); }
ParseDecoder { Map<String, Object> convertJSONObjectToMap(JSONObject object) { Map<String, Object> outputMap = new HashMap<>(); Iterator<String> it = object.keys(); while (it.hasNext()) { String key = it.next(); Object value = object.opt(key); outputMap.put(key, decode(value)); } return outputMap; } protected  ParseDecoder(); static ParseDecoder get(); Object decode(Object object);  }