json数组转成list表

/**
 *  
 *
 * @param jsonArray
 * @param clazz
 * @param 
 * @return
 */
public static <T> List<T> jsonArrayToList(JSONArray jsonArray, Class<T> clazz) {
    if (jsonArray == null) {
        Log.w(TAG, "jsonArray is null");
        return Collections.emptyList();
    }

    List<T> list;
    try {
        list = JSON.parseArray(jsonArray.toJSONString(), clazz);
    } catch (JSONException e) {
        e.printStackTrace();
        Log.e(TAG, "json is error = " + jsonArray);
        list = Collections.emptyList();
    }
    if (list == null || list.size() < 1 || list.isEmpty()) {
        Log.w(TAG, "list is null");
        return Collections.emptyList();
    }

    return list;
}

你可能感兴趣的:(android,java)