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.country.CountryService.java

public JSONArray getCountries(boolean active) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("active", active);

        _command.put("/country/get-countries", _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:it.bradipao.berengar.DbTool.java

public static int json2table(SQLiteDatabase mDB, JSONObject jsonTable) {

    // vars/*  w  w w .  j av  a 2 s.c om*/
    JSONArray jsonRows = new JSONArray();
    JSONArray jsonColsName = new JSONArray();
    JSONArray jsonCols = null;
    ContentValues cv = null;

    int iRes = 0;
    try {
        // init database transaction
        mDB.beginTransaction();
        // fetch table name and drop if exists
        String sTableName = jsonTable.getString("table_name");
        mDB.execSQL("DROP TABLE IF EXISTS " + sTableName);
        if (GOLOG)
            Log.d(LOGTAG, "TABLE NAME : " + sTableName);
        // fetch and execute create sql
        String sTableSql = jsonTable.getString("table_sql");
        mDB.execSQL(sTableSql);
        // fetch columns name
        jsonColsName = jsonTable.getJSONArray("cols_name");
        // fetch rows array
        jsonRows = jsonTable.getJSONArray("rows");
        // iterate through rows
        for (int i = 0; i < jsonRows.length(); i++) {
            // fetch columns
            jsonCols = jsonRows.getJSONArray(i);
            // perform insert
            cv = new ContentValues();
            for (int j = 0; j < jsonCols.length(); j++)
                cv.put(jsonColsName.getString(j), jsonCols.getString(j));
            mDB.insert(sTableName, null, cv);
            if (GOLOG)
                Log.d(LOGTAG, "INSERT IN " + sTableName + " ID=" + jsonCols.getString(0));
        }
        iRes++;
        // set transaction successful
        mDB.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(LOGTAG, "error in json2table", e);
    } finally {
        // end transaction, commit if successful else rollback
        mDB.endTransaction();
    }

    return iRes;
}

From source file:com.port.ocean.shipping.data.VehiclePassedData.java

@Override
protected void onExtractData(JSONObject jsonData) throws Exception {
    JSONArray jsonArray = jsonData.getJSONArray(DATA_TAG);

    dataList = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONArray row = jsonArray.getJSONArray(i);

        if (row.length() > 4) {
            VehiclePassed data = new VehiclePassed();
            data.setLicensePlateNumber(row.getString(0));
            data.setLocation(row.getString(1));
            data.setStorage(row.getString(2));
            data.setAuditTime(row.getString(3));
            data.setAttention("1".equals(row.getString(4)));

            dataList.add(data);/*from w  w w  .  jav a  2s  . c om*/
        }
    }
}

From source file:com.liferay.mobile.android.v62.emailaddress.EmailAddressService.java

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

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

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

        _command.put("/emailaddress/get-email-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:run.ace.NativeHost.java

void send(final JSONArray messages, final CallbackContext callbackContext) {
    final Activity activity = _activity;
    Runnable runnable = new Runnable() {
        public void run() {
            try {
                Object returnValue = null;
                boolean hasReturnValue = false; // Needed because null can be a valid return value
                int numMessages = messages.length();

                for (int i = 0; i < numMessages; i++) {
                    Object instance = null;
                    Handle handle;/*from   w w  w  .ja  v  a  2s .c o m*/
                    JSONArray message = messages.getJSONArray(i);
                    //android.util.Log.d("Ace", "TODO: MSG: " + message);
                    int messageType = message.getInt(0);

                    switch (messageType) {
                    case IncomingMessages.MSG_CREATE:
                        instance = IncomingMessages.create(message, activity);
                        handle = Handle.fromJSONObject(message.getJSONObject(1));
                        handle.register(instance);
                        break;
                    case IncomingMessages.MSG_SET:
                        IncomingMessages.set(message);
                        break;
                    case IncomingMessages.MSG_INVOKE:
                        returnValue = IncomingMessages.invoke(message);
                        hasReturnValue = true;
                        break;
                    case IncomingMessages.MSG_EVENTADD:
                        IncomingMessages.eventAdd(message);
                        break;
                    case IncomingMessages.MSG_EVENTREMOVE:
                        IncomingMessages.eventRemove(message);
                        break;
                    case IncomingMessages.MSG_STATICINVOKE:
                        returnValue = IncomingMessages.staticInvoke(message);
                        hasReturnValue = true;
                        break;
                    case IncomingMessages.MSG_FIELDGET:
                        returnValue = IncomingMessages.fieldGet(message);
                        hasReturnValue = true;
                        break;
                    case IncomingMessages.MSG_STATICFIELDGET:
                        returnValue = IncomingMessages.staticFieldGet(message);
                        hasReturnValue = true;
                        break;
                    case IncomingMessages.MSG_GETINSTANCE:
                        instance = IncomingMessages.getInstance(message, activity, _webView);
                        handle = Handle.fromJSONObject(message.getJSONObject(1));
                        handle.register(instance);
                        break;
                    case IncomingMessages.MSG_NAVIGATE:
                        IncomingMessages.navigate((View) Handle.deserialize(message.getJSONObject(1)),
                                activity);
                        break;
                    case IncomingMessages.MSG_FIELDSET:
                        IncomingMessages.fieldSet(message);
                        break;
                    case IncomingMessages.MSG_PRIVATEFIELDGET:
                        returnValue = IncomingMessages.privateFieldGet(message);
                        hasReturnValue = true;
                        break;
                    default:
                        throw new RuntimeException("Unknown message type: " + messageType);
                    }
                }

                if (numMessages == 1 && hasReturnValue) {
                    // This is a single (non-batched) invoke with a return value
                    // (or a field get).
                    // Send it.
                    // TODO: Need to handle arrays of primitives/objects as well
                    if (Utils.isBoxedNumberOrString(returnValue) || returnValue == null) {
                        // Send the primitive value
                        JSONArray primitive = new JSONArray();
                        primitive.put(returnValue);
                        callbackContext.success(primitive);
                    } else {
                        // Send the object as a handle
                        // Use existing handle if this object already has one
                        Handle handle = Handle.fromObject(returnValue);
                        if (handle == null) {
                            handle = new Handle();
                            handle.register(returnValue);
                        }
                        callbackContext.success(handle.toJSONObject());
                    }
                } else {
                    callbackContext.success();
                }
            } catch (Exception ex) {
                android.util.Log.d("Ace", "Caught exception: " + exceptionWithStackTrace(ex));
                callbackContext.error(exceptionWithStackTrace(ex));
            }
        };
    };
    activity.runOnUiThread(runnable);
}

From source file:com.liferay.mobile.android.v62.blogsentry.BlogsEntryService.java

public JSONArray getCompanyEntries(long companyId, long displayDate, int status, int max) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("companyId", companyId);
        _params.put("displayDate", displayDate);
        _params.put("status", status);
        _params.put("max", max);

        _command.put("/blogsentry/get-company-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.blogsentry.BlogsEntryService.java

public JSONArray getGroupEntries(long groupId, int status, int max) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("status", status);
        _params.put("max", max);

        _command.put("/blogsentry/get-group-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.blogsentry.BlogsEntryService.java

public JSONArray getGroupEntries(long groupId, long displayDate, int status, int max) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("displayDate", displayDate);
        _params.put("status", status);
        _params.put("max", max);

        _command.put("/blogsentry/get-group-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.blogsentry.BlogsEntryService.java

public JSONArray getGroupEntries(long groupId, int status, int start, int end) 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("groupId", groupId);
        _params.put("status", status);
        _params.put("start", start);
        _params.put("end", end);

        _command.put("/blogsentry/get-group-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.blogsentry.BlogsEntryService.java

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

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

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

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

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONArray(0);
}