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.role.RoleService.java

public JSONArray getGroupRoles(long groupId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);

        _command.put("/role/get-group-roles", _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.role.RoleService.java

public JSONArray getUserGroupGroupRoles(long userId, long groupId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("userId", userId);
        _params.put("groupId", groupId);

        _command.put("/role/get-user-group-group-roles", _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.role.RoleService.java

public JSONArray getUserGroupRoles(long userId, long groupId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("userId", userId);
        _params.put("groupId", groupId);

        _command.put("/role/get-user-group-roles", _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.role.RoleService.java

public JSONArray getUserRelatedRoles(long userId, JSONArray groups) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("userId", userId);
        _params.put("groups", checkNull(groups));

        _command.put("/role/get-user-related-roles", _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.role.RoleService.java

public JSONArray getUserRoles(long userId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("userId", userId);

        _command.put("/role/get-user-roles", _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.nolanlawson.cordova.sqlite.SQLitePlugin.java

private SQLitePLuginResult[] execInBackgroundAndReturnResults(JSONArray args) throws JSONException {

    String dbName = args.getString(0);
    JSONArray queries = args.getJSONArray(1);
    boolean readOnly = args.getBoolean(2);
    int numQueries = queries.length();
    SQLitePLuginResult[] results = new SQLitePLuginResult[numQueries];
    SQLiteDatabase db = getDatabase(dbName);

    for (int i = 0; i < numQueries; i++) {
        JSONArray sqlQuery = queries.getJSONArray(i);
        String sql = sqlQuery.getString(0);
        String[] bindArgs = jsonArrayToStringArray(sqlQuery.getJSONArray(1));
        try {//  w  ww  .  java2s . c  o  m
            if (isSelect(sql)) {
                results[i] = doSelectInBackgroundAndPossiblyThrow(sql, bindArgs, db);
            } else { // update/insert/delete
                if (readOnly) {
                    results[i] = new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0,
                            new ReadOnlyException());
                } else {
                    results[i] = doUpdateInBackgroundAndPossiblyThrow(sql, bindArgs, db);
                }
            }
        } catch (Throwable e) {
            if (DEBUG_MODE) {
                e.printStackTrace();
            }
            results[i] = new SQLitePLuginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, e);
        }
    }
    return results;
}

From source file:org.liberty.android.fantastischmemo.downloader.DownloaderSS.java

private void downloadDatabase(DownloadItem di) throws Exception {
    String url = di.getAddress();
    String jsonString = downloaderUtils.downloadJSONString(url);
    JSONObject jsonObject = new JSONObject(jsonString);
    JSONArray jsonDataArray = jsonObject.getJSONArray("data");
    List<Card> cardList = new LinkedList<Card>();
    for (int i = 0; i < jsonDataArray.length(); i++) {
        JSONArray jsonItemArray = jsonDataArray.getJSONArray(i);
        String question = jsonItemArray.getString(0);
        String answer = jsonItemArray.getString(1);
        if (question != null && !question.equals("")) {
            Card card = new Card();
            card.setQuestion(question);/*from  ww  w  .  ja  va  2 s . c o  m*/
            card.setAnswer(answer);
            card.setOrdinal(i + 1);
            card.setCategory(new Category());
            card.setLearningData(new LearningData());
            cardList.add(card);
        }

    }
    String dbname = di.getTitle() + ".db";
    String dbpath = AMEnv.DEFAULT_ROOT_PATH;
    String fullpath = dbpath + dbname;
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(DownloaderSS.this, fullpath);
    try {
        CardDao cardDao = helper.getCardDao();
        cardDao.createCards(cardList);
        long count = helper.getCardDao().getTotalCount(null);
        if (count <= 0L) {
            throw new RuntimeException("Downloaded empty db.");
        }
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
    recentListUtil.addToRecentList(fullpath);
}

From source file:fr.bmartel.android.fadecandy.model.FadecandyDevice.java

public FadecandyDevice(JSONObject fadecandyDevice) {

    try {//  ww  w .j av  a  2s .  c  o m
        if (fadecandyDevice.has(Constants.CONFIG_TYPE) && fadecandyDevice.has(Constants.CONFIG_MAP)) {

            mType = fadecandyDevice.getString(Constants.CONFIG_TYPE);
            JSONArray map = fadecandyDevice.getJSONArray(Constants.CONFIG_MAP);

            for (int i = 0; i < map.length(); i++) {

                JSONArray mapItem = map.getJSONArray(i);
                List<Integer> itemList = new ArrayList<>();
                for (int j = 0; j < mapItem.length(); j++) {
                    itemList.add(mapItem.getInt(j));
                }

                mMap.add(itemList);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.hichinaschool.flashcards.libanki.Models.java

/** Given a joined field string, return available template ordinals */
public ArrayList<Integer> availOrds(JSONObject m, String flds) {
    try {/*from   ww w.j a  v a2  s.  c  om*/
        if (m.getInt("type") == Sched.MODEL_CLOZE) {
            return _availClozeOrds(m, flds);
        }
        String[] fields = Utils.splitFields(flds);
        for (String f : fields) {
            f = f.trim();
        }
        ArrayList<Integer> avail = new ArrayList<Integer>();
        JSONArray reqArray = m.getJSONArray("req");
        for (int i = 0; i < reqArray.length(); i++) {
            JSONArray sr = reqArray.getJSONArray(i);

            int ord = sr.getInt(0);
            String type = sr.getString(1);
            JSONArray req = sr.getJSONArray(2);

            if (type.equals("none")) {
                // unsatisfiable template
                continue;
            } else if (type.equals("all")) {
                // AND requirement?
                boolean ok = true;
                for (int j = 0; j < req.length(); j++) {
                    int idx = req.getInt(j);
                    if (fields[idx] == null || fields[idx].length() == 0) {
                        // missing and was required
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    continue;
                }
            } else if (type.equals("any")) {
                // OR requirement?
                boolean ok = false;
                for (int j = 0; j < req.length(); j++) {
                    int idx = req.getInt(j);
                    if (fields[idx] != null && fields[idx].length() != 0) {
                        // missing and was required
                        ok = true;
                        break;
                    }
                }
                if (!ok) {
                    continue;
                }
            }
            avail.add(ord);
        }
        return avail;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ichi2.anki.dialogs.CustomStudyDialog.java

/**
 * Create a custom study session/*ww  w  .j ava2 s.  c o m*/
 * @param delays delay options for scheduling algorithm
 * @param terms search terms
 * @param resched whether to reschedule the cards based on the answers given (or ignore them if false)
 */
private void createCustomStudySession(JSONArray delays, Object[] terms, Boolean resched) {
    JSONObject dyn;
    final AnkiActivity activity = (AnkiActivity) getActivity();
    Collection col = CollectionHelper.getInstance().getCol(activity);
    try {
        long did = getArguments().getLong("did");
        String deckName = col.getDecks().get(did).getString("name");
        String customStudyDeck = getResources().getString(R.string.custom_study_deck_name);
        JSONObject cur = col.getDecks().byName(customStudyDeck);
        if (cur != null) {
            if (cur.getInt("dyn") != 1) {
                new MaterialDialog.Builder(getActivity()).content(R.string.custom_study_deck_exists)
                        .negativeText(R.string.dialog_cancel).build().show();
                return;
            } else {
                // safe to empty
                col.getSched().emptyDyn(cur.getLong("id"));
                // reuse; don't delete as it may have children
                dyn = cur;
                col.getDecks().select(cur.getLong("id"));
            }
        } else {
            long customStudyDid = col.getDecks().newDyn(customStudyDeck);
            dyn = col.getDecks().get(customStudyDid);
        }
        // and then set various options
        if (delays.length() > 0) {
            dyn.put("delays", delays);
        } else {
            dyn.put("delays", JSONObject.NULL);
        }
        JSONArray ar = dyn.getJSONArray("terms");
        ar.getJSONArray(0).put(0, "deck:\"" + deckName + "\" " + terms[0]);
        ar.getJSONArray(0).put(1, terms[1]);
        ar.getJSONArray(0).put(2, terms[2]);
        dyn.put("resched", resched);
        // Rebuild the filtered deck
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, new DeckTask.TaskListener() {
            @Override
            public void onCancelled() {
            }

            @Override
            public void onPreExecute() {
                activity.showProgressBar();
            }

            @Override
            public void onPostExecute(DeckTask.TaskData result) {
                activity.hideProgressBar();
                ((CustomStudyListener) activity).onCreateCustomStudySession();
            }

            @Override
            public void onProgressUpdate(DeckTask.TaskData... values) {
            }
        });

    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    // Hide the dialogs
    activity.dismissAllDialogFragments();
}