Skip to content

Instantly share code, notes, and snippets.

@thisisone
Created July 29, 2014 11:44
Show Gist options
  • Save thisisone/af6f352a7789f0a5154f to your computer and use it in GitHub Desktop.
Save thisisone/af6f352a7789f0a5154f to your computer and use it in GitHub Desktop.
JAVA JSONObject sample
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