Created
February 9, 2015 07:46
-
-
Save a-v-ebrahimi/283c723b7eae8b42730e to your computer and use it in GitHub Desktop.
Convert LinkedTreeMap key-value pair into JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static JSONObject convertKeyValueToJSON(LinkedTreeMap<String, Object> ltm) { | |
JSONObject jo=new JSONObject(); | |
Object[] objs = ltm.entrySet().toArray(); | |
for (int l=0;l<objs.length;l++) | |
{ | |
Map.Entry o= (Map.Entry) objs[l]; | |
try { | |
if (o.getValue() instanceof LinkedTreeMap) | |
jo.put(o.getKey().toString(),convertKeyValueToJSON((LinkedTreeMap<String, Object>) o.getValue())); | |
else | |
jo.put(o.getKey().toString(),o.getValue()); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
return jo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment