Android Utililty Methods JSON Get

List of utility methods to do JSON Get

Description

The list of methods to do JSON Get are organized into topic(s).

Method

K[]getObjectArray(JSONArray jsonArray, Class clazz)
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;
MapJSONToMap(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;
...
LongjsonToDate(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)));
...
ByteBufferjsonToByteBuffer(JSONObject jsonObj)
json To Byte Buffer
return ByteBuffer.wrap(jsonObj.toString().getBytes(
        Charset.defaultCharset()));