Example usage for org.json JSONArray getJSONArray

List of usage examples for org.json JSONArray getJSONArray

Introduction

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

Prototype

public JSONArray getJSONArray(int index) throws JSONException 

Source Link

Document

Get the JSONArray associated with an index.

Usage

From source file:com.liferay.mobile.android.v62.dlfileentry.DLFileEntryService.java

public JSONArray getGroupFileEntries(long groupId, long userId, long rootFolderId, int start, int end,
        JSONObjectWrapper obc) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("userId", userId);
        _params.put("rootFolderId", rootFolderId);
        _params.put("start", start);
        _params.put("end", end);
        mangleWrapper(_params, "obc", "com.liferay.portal.kernel.util.OrderByComparator", obc);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}

From source file:com.liferay.mobile.android.v62.dlfileentry.DLFileEntryService.java

public JSONArray getGroupFileEntries(long groupId, long userId, long rootFolderId, JSONArray mimeTypes,
        int status, int start, int end, JSONObjectWrapper obc) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("userId", userId);
        _params.put("rootFolderId", rootFolderId);
        _params.put("mimeTypes", checkNull(mimeTypes));
        _params.put("status", status);
        _params.put("start", start);
        _params.put("end", end);
        mangleWrapper(_params, "obc", "com.liferay.portal.kernel.util.OrderByComparator", obc);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}

From source file:com.liferay.mobile.android.v62.address.AddressService.java

public JSONArray getAddresses(String className, long classPK) throws Exception {
    JSONObject _command = new JSONObject();

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

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

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}

From source file:com.android.browser.search.OpenSearchSearchEngine.java

/**
 * Queries for a given search term and returns a cursor containing
 * suggestions ordered by best match.//from  w ww. jav  a2 s.  com
 */
public Cursor getSuggestions(Context context, String query) {
    if (TextUtils.isEmpty(query)) {
        return null;
    }
    if (!isNetworkConnected(context)) {
        Log.i(TAG, "Not connected to network.");
        return null;
    }

    String suggestUri = mSearchEngineInfo.getSuggestUriForQuery(query);
    if (TextUtils.isEmpty(suggestUri)) {
        // No suggest URI available for this engine
        return null;
    }

    try {
        String content = readUrl(suggestUri);
        if (content == null)
            return null;
        /* The data format is a JSON array with items being regular strings or JSON arrays
         * themselves. We are interested in the second and third elements, both of which
         * should be JSON arrays. The second element/array contains the suggestions and the
         * third element contains the descriptions. Some search engines don't support
         * suggestion descriptions so the third element is optional.
         */
        JSONArray results = new JSONArray(content);
        JSONArray suggestions = results.getJSONArray(1);
        JSONArray descriptions = null;
        if (results.length() > 2) {
            descriptions = results.getJSONArray(2);
            // Some search engines given an empty array "[]" for descriptions instead of
            // not including it in the response.
            if (descriptions.length() == 0) {
                descriptions = null;
            }
        }
        return new SuggestionsCursor(suggestions, descriptions);
    } catch (JSONException e) {
        Log.w(TAG, "Error", e);
    }
    return null;
}

From source file:jorge.tolentino.empty.Empty.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArray of arguments for the plugin.
 * @param callbackContext   The callback context used when calling back into JavaScript.
 * @return                  True when the action was valid, false otherwise.
 *//* w ww  . ja  v  a2s.  c  o  m*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("vibrate")) {
        this.vibrate(args.getLong(0));
    } else if (action.equals("vibrateWithPattern")) {
        JSONArray pattern = args.getJSONArray(0);
        int repeat = args.getInt(1);
        long[] patternArray = new long[pattern.length()];
        for (int i = 0; i < pattern.length(); i++) {
            patternArray[i] = pattern.getLong(i);
        }
        this.vibrateWithPattern(patternArray, repeat);
    } else if (action.equals("cancelVibration")) {
        this.cancelVibration();
    } else {
        return false;
    }

    // Only alert and confirm are async.
    callbackContext.success();

    return true;
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public String handleStages(String stageid) {

    try {/*from   w  ww  . j  a  va2  s . co  m*/
        // Format stage_id = [[6,"Today"]]
        if (!stageid.equalsIgnoreCase("false")) {
            JSONArray stage_name = new JSONArray(stageid);
            originialStage = stage_name.getJSONArray(0).getString(1).toString();
            return stage_name.getJSONArray(0).getString(1).toString();
        } else {
            originialStage = "New";
            return "New";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.mixare.data.convert.GeoDataProcessorGeoJSON.java

@Override
public List<Marker> load(String rawData, int taskId, int colour) throws JSONException {
    String id = "";
    String title = "";
    String description = ""; //not used by Mixare
    String URL = "";
    String meaning = ""; //not used by Mixare
    JSONObject geometry = null;//from   w w w.  ja  v a 2s.c o  m
    String type = ""; //not used by Mixare
    JSONArray coordinates = null;
    double lat = 0, lng = 0;

    List<Marker> markers = new ArrayList<Marker>();
    JSONObject root = convertToJSON(rawData);
    Log.v("root", root.toString());
    JSONArray dataArray = root.getJSONArray("features");
    int top = Math.min(MAX_JSON_OBJECTS, dataArray.length());

    Marker ma = null;

    for (int i = 0; i < top; i++) {
        JSONObject object = dataArray.getJSONObject(i);
        JSONObject properties = object.getJSONObject("properties");

        if (properties.has("obj_id")) {
            id = properties.getString("obj_id");
        }

        if (properties.has("title")) {
            title = properties.getString("title");
        }

        if (properties.has("description")) {
            description = properties.getString("description");
        }

        if (properties.has("URL")) {
            URL = properties.getString("URL");
        }

        if (properties.has("meaning")) {
            meaning = properties.getString("meaning");
        }

        geometry = object.getJSONObject("geometry");

        if (geometry.has("type")) {
            type = geometry.getString("type");
        }

        if (geometry.has("coordinates")) {
            coordinates = geometry.getJSONArray("coordinates");
        }

        if (type.equals("Point")) {

            lat = (Double) coordinates.get(0);
            lng = (Double) coordinates.get(1);

            ma = new POIMarker(id, HtmlUnescape.unescapeHTML(title), meaning, lat, lng, 0, // elevation to be implemented, 
                    URL, taskId, colour);

            markers.add(ma);
        }

        if (type.equals("MultiPoint")) {
            int length = coordinates.length();
            for (int j = 0; j < length; j++) {
                JSONArray sub_coordinates = coordinates.getJSONArray(j);
                lat = (Double) sub_coordinates.get(0);
                lng = (Double) sub_coordinates.get(1);

                ma = new POIMarker(id, HtmlUnescape.unescapeHTML(title), meaning, lat, lng, 0, // elevation to be implemented, 
                        URL, taskId, colour);

                markers.add(ma);
            }
        }
    }

    return markers;
}

From source file:com.liferay.mobile.android.v7.commentmanagerjsonws.CommentmanagerjsonwsService.java

public JSONArray getComments(long commentId, int start, int end) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("commentId", commentId);
        _params.put("start", start);
        _params.put("end", end);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}

From source file:com.liferay.mobile.android.v7.commentmanagerjsonws.CommentmanagerjsonwsService.java

public JSONArray getComments(long groupId, String className, long classPK, int start, int end)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("className", checkNull(className));
        _params.put("classPK", classPK);
        _params.put("start", start);
        _params.put("end", end);

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}

From source file:com.wholegroup.rally.Rally.java

/**
 * ??   JSON ?.//from w w  w  . ja  va 2  s.  c o m
 */
public void fromJSON(String strJSON) {
    try {
        JSONObject jsonObject = new JSONObject(strJSON);
        JSONArray jsonArray;
        JSONArray jsonArray2;

        jsonArray = jsonObject.getJSONArray("m_arrField");

        for (int y = 0; y < jsonArray.length(); y++) {
            if (FIELDHEIGHT <= y) {
                break;
            }

            jsonArray2 = jsonArray.getJSONArray(y);

            for (int x = 0; x < jsonArray2.length(); x++) {
                if (FIELDWIDTH <= x) {
                    break;
                }

                m_arrField[y][x] = jsonArray2.getInt(x);
            }
        }

        m_iScore = jsonObject.getInt("m_iScore");
        m_iTypeGame = jsonObject.getInt("m_iTypeGame");
        m_iPlayerPos = jsonObject.getInt("m_iPlayerPos");
        m_iLifeCount = jsonObject.getInt("m_iLifeCount");
        m_iDensity = jsonObject.getInt("m_iDensity");
        m_iSpeedMS = jsonObject.getInt("m_iSpeedMS");
    } catch (JSONException e) {
        e.printStackTrace();
    }
}