Created
July 29, 2014 11:44
-
-
Save thisisone/af6f352a7789f0a5154f to your computer and use it in GitHub Desktop.
JAVA JSONObject sample
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
try | |
{ | |
JSONObject json = new JSONObject(); | |
json.put("int", 1); | |
json.put("float", 1.1f); | |
json.put("bool", true); | |
json.put("string", "hello"); | |
JSONArray jarr = new JSONArray(); | |
jarr.put("abc"); | |
jarr.put("def"); | |
json.put("list", jarr); | |
Log.d("Unity", "json="+json.toString()); | |
json = new JSONObject(json.toString()); | |
Log.d("Unity", "float"+json.get("float")); | |
} | |
catch(JSONException e) | |
{ | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
e.printStackTrace(pw); | |
String msg = sw.toString(); | |
Log.e("Unity", "JSONException: "+msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment