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.hichinaschool.flashcards.libanki.sync.Syncer.java

private void mergeDecks(JSONArray rchg) {
    try {//  w w w  .j  a v  a 2s .  co  m
        JSONArray decks = rchg.getJSONArray(0);
        for (int i = 0; i < decks.length(); i++) {
            JSONObject r = decks.getJSONObject(i);
            JSONObject l = mCol.getDecks().get(r.getLong("id"), false);
            // if missing locally or server is newer, update
            if (l == null || r.getLong("mod") > l.getLong("mod")) {
                mCol.getDecks().update(r);
            }
        }
        JSONArray confs = rchg.getJSONArray(1);
        for (int i = 0; i < confs.length(); i++) {
            JSONObject r = confs.getJSONObject(i);
            JSONObject l = mCol.getDecks().getConf(r.getLong("id"));
            // if missing locally or server is newer, update
            if (l == null || r.getLong("mod") > l.getLong("mod")) {
                mCol.getDecks().updateConf(r);
            }
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.sync.Syncer.java

/**
 * Cards/notes/revlog ********************************************************************
 *///from   ww  w  .  j  av a  2 s.c  om

private void mergeRevlog(JSONArray logs) {
    for (int i = 0; i < logs.length(); i++) {
        try {
            mCol.getDb().execute("INSERT OR IGNORE INTO revlog VALUES (?,?,?,?,?,?,?,?,?)",
                    ConvUtils.jsonArray2Objects(logs.getJSONArray(i)));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

}

From source file:com.hichinaschool.flashcards.libanki.sync.Syncer.java

private ArrayList<Object[]> newerRows(JSONArray data, String table, int modIdx) {
    long[] ids = new long[data.length()];
    try {//from w ww  .ja  v a2  s.  c  om
        for (int i = 0; i < data.length(); i++) {
            ids[i] = data.getJSONArray(i).getLong(0);
        }
        HashMap<Long, Long> lmods = new HashMap<Long, Long>();
        Cursor cur = null;
        try {
            cur = mCol.getDb().getDatabase().rawQuery(
                    "SELECT id, mod FROM " + table + " WHERE id IN " + Utils.ids2str(ids) + " AND " + usnLim(),
                    null);
            while (cur.moveToNext()) {
                lmods.put(cur.getLong(0), cur.getLong(1));
            }
        } finally {
            if (cur != null && !cur.isClosed()) {
                cur.close();
            }
        }
        ArrayList<Object[]> update = new ArrayList<Object[]>();
        for (int i = 0; i < data.length(); i++) {
            JSONArray r = data.getJSONArray(i);
            if (!lmods.containsKey(r.getLong(0)) || lmods.get(r.getLong(0)) < r.getLong(modIdx)) {
                update.add(ConvUtils.jsonArray2Objects(r));
            }
        }
        return update;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.kupriyanov.android.apps.translate.service.WorkerThread.java

public static String detectLanguage(String apiQuery) throws ApiException, ParseException {

    String content = getUrlContent(apiQuery);

    Log.d(TAG, "[RESPONSE->]:" + content);

    try {/*from w ww .j a va2 s. c  o m*/
        // Drill into the JSON response to find the content body
        final JSONObject response = new JSONObject(content);
        final JSONObject data = response.getJSONObject("data");
        final JSONArray detections = data.getJSONArray("detections");
        final JSONArray detectionArr = detections.getJSONArray(0);
        final JSONObject detectionObj = detectionArr.getJSONObject(0);

        //       language": "de",
        //        "isReliable": false,
        //        "confidence": 1.0

        return detectionObj.getString("language");
    } catch (JSONException e) {
        throw new ParseException("Problem parsing API response:" + content, e);
    }

}

From source file:com.liferay.mobile.android.v7.ddmstructureversion.DdmstructureversionService.java

public JSONArray getStructureVersions(long structureId, int start, int end, JSONObjectWrapper orderByComparator)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("structureId", structureId);
        _params.put("start", start);
        _params.put("end", end);
        mangleWrapper(_params, "orderByComparator",
                "com.liferay.portal.kernel.util.OrderByComparator<com.liferay.dynamic.data.mapping.model.DDMStructureVersion>",
                orderByComparator);

        _command.put("/ddm.ddmstructureversion/get-structure-versions", _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.norman0406.slimgress.API.Plext.PlextBase.java

protected PlextBase(PlextType type, JSONArray json) throws JSONException {
    super(json);//from w w  w  . j  a v a2  s .  c o  m
    mPlextType = type;

    JSONObject item = json.getJSONObject(2);

    JSONObject plext = item.getJSONObject("plext");
    JSONArray markup = plext.getJSONArray("markup");

    mText = plext.getString("text");

    mMarkups = new LinkedList<Markup>();
    for (int i = 0; i < markup.length(); i++) {
        JSONArray markupItem = markup.getJSONArray(i);

        Markup newMarkup = Markup.createByJSON(markupItem);
        if (newMarkup != null)
            mMarkups.add(newMarkup);
    }
}

From source file:com.liferay.mobile.android.v7.mbcategory.MBCategoryService.java

public JSONArray getCategories(long groupId, long parentCategoryId, int status, int start, int end)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("parentCategoryId", parentCategoryId);
        _params.put("status", status);
        _params.put("start", start);
        _params.put("end", end);

        _command.put("/mbcategory/get-categories", _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.mbcategory.MBCategoryService.java

public JSONArray getCategories(long groupId, long excludedCategoryId, long parentCategoryId, int status,
        int start, int end) throws Exception {
    JSONObject _command = new JSONObject();

    try {/*ww  w .ja va 2s .co m*/
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("excludedCategoryId", excludedCategoryId);
        _params.put("parentCategoryId", parentCategoryId);
        _params.put("status", status);
        _params.put("start", start);
        _params.put("end", end);

        _command.put("/mbcategory/get-categories", _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.mbcategory.MBCategoryService.java

public JSONArray getCategories(long groupId, long parentCategoryId, int start, int end) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("parentCategoryId", parentCategoryId);
        _params.put("start", start);
        _params.put("end", end);

        _command.put("/mbcategory/get-categories", _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.mbcategory.MBCategoryService.java

public JSONArray getCategories(long groupId, JSONArray parentCategoryIds, int start, int end) throws Exception {
    JSONObject _command = new JSONObject();

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

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

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}