JSONUtils { public static String getString(JSONObject obj, String field) { if (obj == null || StringUtils.isEmpty(field)) { return null; } try { return (String) obj.get(field); } catch (JSONException e) { e.printStackTrace(); return null; } }  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 testGetString() throws ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse("{\"id\":\"application_1479206441898_30784\",\"isYhd\":\"pms\"}"); Assert.assertEquals("application_1479206441898_30784", JSONUtils.getString(jsonObject, "id")); }