JSONParser { public String parseString(JSONObject object, String name) { try { return object.getString(name); } catch (JSONException e) { if (DEBUG) Log.e(TAG, "No string value for " + name, e); return ""; } }  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_parseString() throws Exception { JSONObject object = new JSONObject(); object.put("test", "test object"); assertEquals("test object", parser.parseString(object, "test")); }
@Test public void test_parseString_null() throws Exception { JSONObject object = new JSONObject(); object.put("test", "test object"); assertEquals("", parser.parseString(object, "not_valid")); }