Example usage for org.json JSONArray getInt

List of usage examples for org.json JSONArray getInt

Introduction

In this page you can find the example usage for org.json JSONArray getInt.

Prototype

public int getInt(int index) throws JSONException 

Source Link

Document

Get the int value associated with an index.

Usage

From source file:com.mm.yamingapp.core.MethodDescriptor.java

/**
 * Converts a parameter from JSON into a Java Object.
 * /*from  w w w .  j a  v a  2 s .c o m*/
 * @return TODO
 */
// TODO(damonkohler): This signature is a bit weird (auto-refactored). The obvious alternative
// would be to work on one supplied parameter and return the converted parameter. However, that's
// problematic because you lose the ability to call the getXXX methods on the JSON array.
@VisibleForTesting
static Object convertParameter(final JSONArray parameters, int index, Type type)
        throws JSONException, RpcError {
    try {
        // We must handle null and numbers explicitly because we cannot magically cast them. We
        // also need to convert implicitly from numbers to bools.
        if (parameters.isNull(index)) {
            return null;
        } else if (type == Boolean.class) {
            try {
                return parameters.getBoolean(index);
            } catch (JSONException e) {
                return new Boolean(parameters.getInt(index) != 0);
            }
        } else if (type == Long.class) {
            return parameters.getLong(index);
        } else if (type == Double.class) {
            return parameters.getDouble(index);
        } else if (type == Integer.class) {
            return parameters.getInt(index);
        } else {
            // Magically cast the parameter to the right Java type.
            return ((Class<?>) type).cast(parameters.get(index));
        }
    } catch (ClassCastException e) {
        throw new RpcError(
                "Argument " + (index + 1) + " should be of type " + ((Class<?>) type).getSimpleName() + ".");
    }
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getActivitiesCount(long mirrorActivityId, long classNameId, long classPK) throws Exception {
    JSONObject _command = new JSONObject();

    try {/* w  ww  .  j  a  v  a  2 s  .  c  o  m*/
        JSONObject _params = new JSONObject();

        _params.put("mirrorActivityId", mirrorActivityId);
        _params.put("classNameId", classNameId);
        _params.put("classPK", classPK);

        _command.put("/socialactivity/get-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getActivitiesCount(String className) throws Exception {
    JSONObject _command = new JSONObject();

    try {//  w ww .  j av  a 2 s  .  com
        JSONObject _params = new JSONObject();

        _params.put("className", checkNull(className));

        _command.put("/socialactivity/get-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getActivitiesCount(long mirrorActivityId, String className, long classPK) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from w  w  w  . ja v  a  2 s  .c  o m*/
        JSONObject _params = new JSONObject();

        _params.put("mirrorActivityId", mirrorActivityId);
        _params.put("className", checkNull(className));
        _params.put("classPK", classPK);

        _command.put("/socialactivity/get-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getActivitiesCount(long classNameId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from www.j a v a2s  .c  o  m*/
        JSONObject _params = new JSONObject();

        _params.put("classNameId", classNameId);

        _command.put("/socialactivity/get-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getGroupActivitiesCount(long groupId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from ww w.j a v  a  2s .c  om*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);

        _command.put("/socialactivity/get-group-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getGroupUsersActivitiesCount(long groupId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*from w ww .  ja v a  2s. c om*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);

        _command.put("/socialactivity/get-group-users-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getOrganizationActivitiesCount(long organizationId) throws Exception {
    JSONObject _command = new JSONObject();

    try {/* w  w w  .j av  a  2  s  . c o  m*/
        JSONObject _params = new JSONObject();

        _params.put("organizationId", organizationId);

        _command.put("/socialactivity/get-organization-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getOrganizationUsersActivitiesCount(long organizationId) throws Exception {
    JSONObject _command = new JSONObject();

    try {//from   w w  w  . j a  va 2 s  . co m
        JSONObject _params = new JSONObject();

        _params.put("organizationId", organizationId);

        _command.put("/socialactivity/get-organization-users-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}

From source file:com.liferay.mobile.android.v7.socialactivity.SocialActivityService.java

public Integer getRelationActivitiesCount(long userId) throws Exception {
    JSONObject _command = new JSONObject();

    try {//from  ww w .  j a  v a 2s.  c  o m
        JSONObject _params = new JSONObject();

        _params.put("userId", userId);

        _command.put("/socialactivity/get-relation-activities-count", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

    if (_result == null) {
        return null;
    }

    return _result.getInt(0);
}