Created
April 19, 2013 21:02
-
-
Save emmettbutler/5423202 to your computer and use it in GitHub Desktop.
Example of creating a JSON string from a Java HashMap - used in https://github.com/emmett9001/parsely-android/blob/master/HiParsely/src/com/parsely/parselyandroid/ParselyTracker.java#L313
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
private String JsonEncode(Map<String, Object> map){ | |
ObjectMapper mapper = new ObjectMapper(); | |
String ret = null; | |
try { | |
StringWriter strWriter = new StringWriter(); | |
mapper.writeValue(strWriter, map); | |
ret = strWriter.toString(); | |
} catch (JsonGenerationException e) { | |
e.printStackTrace(); | |
} catch (JsonMappingException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment