JSONUtils { public static Boolean getBoolean(JSONObject obj, String field) { if (obj == null || StringUtils.isEmpty(field)) { return false; } try { return (Boolean) obj.get(field); } catch (JSONException e) { e.printStackTrace(); return false; } }  static String getString(JSONObject obj, String field); static int getInt(JSONObject obj, String field); static long getLong(JSONObject obj, String field); static long getLong(JSONObject obj, String field, long defaultValue); static Boolean getBoolean(JSONObject obj, String field); static JSONObject getJSONObject(JSONObject obj, String field); static JSONArray getJSONArray(JSONObject obj, String field);  }
@Test public void testGetBoolean() throws ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse("{\"id\":\"application_1479206441898_30784\",\"isYhd\":true}"); Assert.assertEquals(Boolean.TRUE, JSONUtils.getBoolean(jsonObject, "isYhd")); jsonObject = (JSONObject) parser.parse("{\"id\":\"application_1479206441898_30784\",\"isYhd\":false}"); Assert.assertEquals(Boolean.FALSE, JSONUtils.getBoolean(jsonObject, "isYhd")); }