Example usage for org.json JSONArray getJSONObject

List of usage examples for org.json JSONArray getJSONObject

Introduction

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

Prototype

public JSONObject getJSONObject(int index) throws JSONException 

Source Link

Document

Get the JSONObject associated with an index.

Usage

From source file:com.liferay.mobile.android.v62.phone.PhoneService.java

public JSONObject getPhone(long phoneId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("phoneId", phoneId);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.liferay.mobile.android.v62.phone.PhoneService.java

public JSONObject updatePhone(long phoneId, String number, String extension, int typeId, boolean primary)
        throws Exception {
    JSONObject _command = new JSONObject();

    try {/*  w w  w. j ava  2 s .  com*/
        JSONObject _params = new JSONObject();

        _params.put("phoneId", phoneId);
        _params.put("number", checkNull(number));
        _params.put("extension", checkNull(extension));
        _params.put("typeId", typeId);
        _params.put("primary", primary);

        _command.put("/phone/update-phone", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.endofhope.neurasthenia.bayeux.BayeuxMessage.java

public BayeuxMessage(String jsonMessage) throws JSONException {
    JSONTokener jsont = new JSONTokener(jsonMessage);
    JSONArray jsona = new JSONArray(jsont);
    // FIXME ? msg   .
    JSONObject jsono = jsona.getJSONObject(0);
    // channel //ww w.  j av a  2  s  .  c o  m
    channel = jsono.getString("channel");
    if (channel != null && channel.startsWith("/meta/")) {
        if ("/meta/handshake".equals(channel)) {
            // type 
            type = BayeuxMessage.HANDSHAKE_REQ;
            // version 
            version = jsono.getString("version");
            JSONArray jsonaSupportedConnectionTypes = jsono.getJSONArray("supportedConnectionTypes");
            supportedConnectionTypesList = new ArrayList<String>();
            // supportedConnectionTypes 
            for (int i = 0; i < jsonaSupportedConnectionTypes.length(); i++) {
                supportedConnectionTypesList.add(jsonaSupportedConnectionTypes.getString(i));
            }
            // Handshake req ?  mandatory ? ? ?.
        } else if ("/meta/connect".equals(channel)) {
            type = BayeuxMessage.CONNECT_REQ;
            clientId = jsono.getString("clientId");
            connectionType = jsono.getString("connectionType");
        } else if ("/meta/disconnect".equals(channel)) {
            type = BayeuxMessage.DISCONNECT_REQ;
            clientId = jsono.getString("clientId");
        } else if ("/meta/subscribe".equals(channel)) {
            type = BayeuxMessage.SUBSCRIBE_REQ;
            clientId = jsono.getString("clientId");
            subscription = jsono.getString("subscription");
        } else if ("/meta/unsubscribe".equals(channel)) {
            type = BayeuxMessage.UNSUBSCRIBE_REQ;
            clientId = jsono.getString("clientId");
            subscription = jsono.getString("subscription");
        }
    } else {
        type = BayeuxMessage.PUBLISH_REQ;
        data = jsono.getString("data");
    }
}

From source file:com.jsonstore.util.JSONStoreUtil.java

public static List<JSONObject> convertJSONArrayToJSONObjectList(JSONArray arr) {
    List<JSONObject> results = new LinkedList<JSONObject>();
    if (arr != null) {
        for (int i = 0; i < arr.length(); i++) {
            try {
                results.add(arr.getJSONObject(i));
            } catch (JSONException e) {
                //Do nothing. Ignore this entry
            }/*from  w  w  w .  ja  v a 2 s. co  m*/
        }
    }

    return results;
}

From source file:salvatejero.cordova.liferay.LiferayPlugin.java

protected JSONObject getGuestGroupId(Session session) throws Exception {
    long groupId = -1;
    GroupService groupService = new GroupService(session);
    JSONArray groups = groupService.getUserSites();
    for (int i = 0; i < groups.length(); i++) {
        JSONObject group = groups.getJSONObject(i);
        String name = group.getString("name");
        if (!name.equals("Guest")) {
            continue;
        }/*from  ww  w  . jav a  2 s . c  o m*/
        return group;
    }
    if (groupId == -1) {
        throw new Exception("Couldn't find Guest group.");
    }
    return null;
}

From source file:com.liferay.mobile.android.v62.mdraction.MDRActionService.java

public JSONObject addAction(long ruleGroupInstanceId, JSONObject nameMap, JSONObject descriptionMap,
        String type, String typeSettings, JSONObjectWrapper serviceContext) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*  w  ww.  java2s. co m*/
        JSONObject _params = new JSONObject();

        _params.put("ruleGroupInstanceId", ruleGroupInstanceId);
        _params.put("nameMap", checkNull(nameMap));
        _params.put("descriptionMap", checkNull(descriptionMap));
        _params.put("type", checkNull(type));
        _params.put("typeSettings", checkNull(typeSettings));
        mangleWrapper(_params, "serviceContext", "com.liferay.portal.service.ServiceContext", serviceContext);

        _command.put("/mdraction/add-action", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.liferay.mobile.android.v62.mdraction.MDRActionService.java

public JSONObject addAction(long ruleGroupInstanceId, JSONObject nameMap, JSONObject descriptionMap,
        String type, JSONObjectWrapper typeSettingsProperties, JSONObjectWrapper serviceContext)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("ruleGroupInstanceId", ruleGroupInstanceId);
        _params.put("nameMap", checkNull(nameMap));
        _params.put("descriptionMap", checkNull(descriptionMap));
        _params.put("type", checkNull(type));
        mangleWrapper(_params, "typeSettingsProperties", "com.liferay.portal.kernel.util.UnicodeProperties",
                typeSettingsProperties);
        mangleWrapper(_params, "serviceContext", "com.liferay.portal.service.ServiceContext", serviceContext);

        _command.put("/mdraction/add-action", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.liferay.mobile.android.v62.mdraction.MDRActionService.java

public JSONObject fetchAction(long actionId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("actionId", actionId);

        _command.put("/mdraction/fetch-action", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.liferay.mobile.android.v62.mdraction.MDRActionService.java

public JSONObject getAction(long actionId) throws Exception {
    JSONObject _command = new JSONObject();

    try {//from  w ww .ja va2s .  c  o  m
        JSONObject _params = new JSONObject();

        _params.put("actionId", actionId);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:com.liferay.mobile.android.v62.mdraction.MDRActionService.java

public JSONObject updateAction(long actionId, JSONObject nameMap, JSONObject descriptionMap, String type,
        String typeSettings, JSONObjectWrapper serviceContext) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("actionId", actionId);
        _params.put("nameMap", checkNull(nameMap));
        _params.put("descriptionMap", checkNull(descriptionMap));
        _params.put("type", checkNull(type));
        _params.put("typeSettings", checkNull(typeSettings));
        mangleWrapper(_params, "serviceContext", "com.liferay.portal.service.ServiceContext", serviceContext);

        _command.put("/mdraction/update-action", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}