List of utility methods to do JSON Get
K[] | getObjectArray(JSONArray jsonArray, Class A helper method to convert multi dimensional JSONArrays to ObjectArrays of Class clazz. K[] result = (K[]) Array.newInstance(clazz, jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { try { result[i] = clazz.getConstructor(JSONObject.class) .newInstance(jsonArray.getJSONObject(i)); } catch (Exception e) { e.printStackTrace(); return result; |
Map | JSONToMap(JSONObject obj) JSON To Map Map<String, String> map = new HashMap<String, String>(); @SuppressWarnings("unchecked") Iterator<String> it = obj.keys(); while (it.hasNext()) { String key = it.next(); map.put(key, obj.getString(key)); return map; ... |
Long | jsonToDate(String jsonString) json To Date Calendar calendar = Calendar.getInstance(); int indexOfPlus = jsonString.indexOf("+"); int startOfDate = 5; if (jsonString.startsWith("/")) { startOfDate = 6; calendar.setTimeInMillis(Long.parseLong(jsonString.substring( startOfDate, indexOfPlus > 0 ? indexOfPlus : jsonString.length() - 2))); ... |
ByteBuffer | jsonToByteBuffer(JSONObject jsonObj) json To Byte Buffer return ByteBuffer.wrap(jsonObj.toString().getBytes(
Charset.defaultCharset()));
|