JSONParser { public boolean parseBoolean(JSONObject object, String name) { try { return object.getBoolean(name); } catch (JSONException e) { if (DEBUG) Log.e(TAG, "No boolean value for " + name, e); return false; } }  String parseString(JSONObject object, String name); long parseLong(JSONObject object, String name); boolean parseBoolean(JSONObject object, String name); JSONObject parseJSONObject(JSONObject object, String name); JSONArray parseJSONArray(JSONObject object, String name);  }
@Test public void test_parseBoolean() throws Exception { JSONObject object = new JSONObject(); object.put("test", true); assertEquals(true, parser.parseBoolean(object, "test")); }
@Test public void test_parseBoolean_null() throws Exception { JSONObject object = new JSONObject(); object.put("test", true); assertEquals(false, parser.parseBoolean(object, "not_valid")); }