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.v7.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 w w. j a  v  a  2 s.co  m
        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<com.liferay.document.library.kernel.model.DLFileEntry>",
                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.v7.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 {/*ww  w .  j  a  v a  2s.c  o m*/
        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<com.liferay.document.library.kernel.model.DLFileEntry>",
                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.v7.dlfileentry.DLFileEntryService.java

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

    try {//w  ww .java  2 s  .  c o m
        JSONObject _params = new JSONObject();

        _params.put("groupId", groupId);
        _params.put("userId", userId);
        _params.put("repositoryId", repositoryId);
        _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<com.liferay.document.library.kernel.model.DLFileEntry>",
                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.phonegap.ContactManager.java

/**
 * Executes the request and returns PluginResult.
 * //from ww w . ja  va2  s  .  c  o m
 * @param action       The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId   The callback id used when calling back into JavaScript.
 * @return             A PluginResult object with a status and message.
 */
public PluginResult execute(String action, JSONArray args, String callbackId) {
    if (contactAccessor == null) {
        contactAccessor = ContactAccessor.getInstance(webView, ctx);
    }
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("search")) {
            JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
            return new PluginResult(status, res, "navigator.service.contacts.cast");
        } else if (action.equals("save")) {
            return new PluginResult(status, contactAccessor.save(args.getJSONObject(0)));
        } else if (action.equals("remove")) {
            if (contactAccessor.remove(args.getString(0))) {
                return new PluginResult(status, result);
            } else {
                JSONObject r = new JSONObject();
                r.put("code", 2);
                return new PluginResult(PluginResult.Status.ERROR, r);
            }
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:org.hyperledger.common.Base58Test.java

@Test
public void base58encode() throws IOException, JSONException, HyperLedgerException {
    JSONArray testData = readObjectArray(BASE58_ENCODE);
    for (int i = 0; i < testData.length(); ++i) {
        JSONArray test = testData.getJSONArray(i);
        assertTrue(ByteUtils.toBase58(ByteUtils.fromHex(test.getString(0))).equals(test.get(1)));
        assertTrue(ByteUtils.toHex(ByteUtils.fromBase58(test.getString(1))).equals(test.get(0)));
    }//from  www .  j av a  2s  . co  m
}

From source file:org.streetpacman.util.DMUtils.java

public static List<DMGeoPoint> JSONArray2GeoPoints(JSONArray jsonArray) throws JSONException {
    List<DMGeoPoint> ptList = new ArrayList<DMGeoPoint>();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONArray jsonPoint = jsonArray.getJSONArray(i);
        int x = (int) (new Double(jsonPoint.getString(0)) * 1E6);
        int y = (int) (new Double(jsonPoint.getString(1)) * 1E6);
        ptList.add(new DMGeoPoint(x, y));
    }//  www  .j a v a  2 s  . c  o m
    return ptList;
}

From source file:net.geco.model.iojson.PersistentStore.java

public void importControls(JSONStore store, Registry registry) throws JSONException {
    if (store.has(K.CONTROLS)) { // MIRG 2.x -> 2.2
        JSONArray controls = store.getJSONArray(K.CONTROLS);
        for (int i = 0; i < controls.length(); i++) {
            JSONArray codeData = controls.getJSONArray(i);
            registry.setControlPenalty(codeData.getInt(0), new Date(codeData.getLong(1)));
        }/*from   w w w  .ja v  a2 s  .  c o m*/
    }
}

From source file:net.geco.model.iojson.PersistentStore.java

public void importRunnersData(JSONStore store, Registry registry, Factory factory) throws JSONException {
    final int I_RUNNER = 0;
    final int I_ECARD = 1;
    final int I_RESULT = 2;
    JSONArray runnersData = store.getJSONArray(K.RUNNERS_DATA);
    for (int i = 0; i < runnersData.length(); i++) {
        JSONArray runnerTuple = runnersData.getJSONArray(i);

        JSONObject c = runnerTuple.getJSONObject(I_RUNNER);
        Runner runner = factory.createRunner();
        runner.setStartId(c.getInt(K.START_ID));
        runner.setFirstname(c.getString(K.FIRST));
        runner.setLastname(c.getString(K.LAST));
        runner.setEcard(c.getString(K.ECARD));
        runner.setClub(store.retrieve(c.getInt(K.CLUB), Club.class));
        runner.setCategory(store.retrieve(c.getInt(K.CAT), Category.class));
        runner.setCourse(store.retrieve(c.getInt(K.COURSE), Course.class));
        runner.setRegisteredStarttime(new Date(c.getLong(K.START)));
        runner.setArchiveId((Integer) c.opt(K.ARK));
        runner.setRentedEcard(c.optBoolean(K.RENT));
        runner.setNC(c.optBoolean(K.NC));
        registry.addRunner(runner);//from   ww  w  . j  a  va 2s  .  c  o  m

        JSONObject d = runnerTuple.getJSONObject(I_ECARD);
        RunnerRaceData raceData = factory.createRunnerRaceData();
        raceData.setStarttime(new Date(d.getLong(K.START)));
        raceData.setFinishtime(new Date(d.getLong(K.FINISH)));
        raceData.setControltime(new Date(d.getLong(K.CHECK)));
        raceData.setReadtime(new Date(d.getLong(K.READ)));
        JSONArray p = d.getJSONArray(K.PUNCHES);
        Punch[] punches = new Punch[p.length() / 2];
        for (int j = 0; j < punches.length; j++) {
            punches[j] = factory.createPunch();
            punches[j].setCode(p.getInt(2 * j));
            punches[j].setTime(new Date(p.getLong(2 * j + 1)));
        }
        raceData.setPunches(punches);
        raceData.setRunner(runner);
        registry.addRunnerData(raceData);

        JSONObject r = runnerTuple.getJSONObject(I_RESULT);
        TraceData traceData = factory.createTraceData();
        traceData.setNbMPs(r.getInt(K.MPS));
        traceData.setNbExtraneous(r.optInt(K.EXTRA)); // MIGR v2.x -> v2.3
        JSONArray t = r.getJSONArray(K.TRACE);
        Trace[] trace = new Trace[t.length() / 2];
        for (int j = 0; j < trace.length; j++) {
            trace[j] = factory.createTrace(t.getString(2 * j), new Date(t.getLong(2 * j + 1)));
        }
        if (r.has(K.SECTION_DATA)) {
            SectionTraceData sectionData = (SectionTraceData) traceData;
            JSONArray sections = r.getJSONArray(K.SECTION_DATA);
            for (int j = 0; j < sections.length(); j++) {
                JSONArray section = sections.getJSONArray(j);
                sectionData.putSectionAt(store.retrieve(section.getInt(0), Section.class), section.getInt(1));
            }
        }
        JSONArray neut = r.getJSONArray(K.NEUTRALIZED);
        for (int j = 0; j < neut.length(); j++) {
            trace[neut.getInt(j)].setNeutralized(true);
        }
        traceData.setTrace(trace);
        raceData.setTraceData(traceData);

        RunnerResult result = factory.createRunnerResult();
        result.setRaceTime(r.optLong(K.RACE_TIME, TimeManager.NO_TIME_l)); // MIGR v2.x -> v2.2
        result.setResultTime(r.getLong(K.TIME));
        result.setStatus(Status.valueOf(r.getString(K.STATUS)));
        result.setTimePenalty(r.getLong(K.PENALTY));
        result.setManualTimePenalty(r.optLong(K.MANUAL_PENALTY, 0)); // MIGR v2.x -> v2.3
        raceData.setResult(result);
    }
}

From source file:com.markupartist.sthlmtraveling.provider.planner.Planner.java

public Trip2 addIntermediateStops(final Context context, Trip2 trip, JourneyQuery query) throws IOException {
    Uri u = Uri.parse(apiEndpoint2());/*w w w.  jav  a 2  s . com*/
    Uri.Builder b = u.buildUpon();
    b.appendEncodedPath("journey/v1/intermediate/");
    b.appendQueryParameter("ident", query.ident);
    b.appendQueryParameter("seqnr", query.seqnr);
    int references = 0;
    String reference = null;
    for (SubTrip st : trip.subTrips) {
        if ((!TextUtils.isEmpty(st.reference)) && st.intermediateStop.isEmpty()) {
            b.appendQueryParameter("reference", st.reference);
            references++;
            reference = st.reference;
        }
    }
    u = b.build();

    if (references == 0) {
        return trip;
    }

    HttpHelper httpHelper = HttpHelper.getInstance(context);
    HttpURLConnection connection = httpHelper.getConnection(u.toString());

    String rawContent;
    int statusCode = connection.getResponseCode();
    switch (statusCode) {
    case 200:
        rawContent = httpHelper.getBody(connection);
        try {
            JSONObject baseResponse = new JSONObject(rawContent);
            if (baseResponse.has("stops")) {
                if (baseResponse.isNull("stops")) {
                    Log.d(TAG, "stops was null, ignoring.");
                } else if (references == 1) {
                    JSONArray intermediateStopsJson = baseResponse.getJSONArray("stops");
                    for (SubTrip st : trip.subTrips) {
                        if (reference.equals(st.reference)) {
                            for (int i = 0; i < intermediateStopsJson.length(); i++) {
                                st.intermediateStop
                                        .add(IntermediateStop.fromJson(intermediateStopsJson.getJSONObject(i)));
                            }
                        }
                    }
                } else {
                    JSONObject intermediateStopsJson = baseResponse.getJSONObject("stops");
                    for (SubTrip st : trip.subTrips) {
                        if (intermediateStopsJson.has(st.reference)) {
                            JSONArray jsonArray = intermediateStopsJson.getJSONArray(st.reference);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                st.intermediateStop.add(IntermediateStop.fromJson(jsonArray.getJSONObject(i)));
                            }
                        }
                    }
                }

            } else {
                Log.w(TAG, "Invalid response when fetching intermediate stops.");
            }
        } catch (JSONException e) {
            Log.w(TAG, "Could not parse the reponse for intermediate stops.");
        }
        break;
    case 400: // Bad request
        rawContent = httpHelper.getErrorBody(connection);
        try {
            BadResponse br = BadResponse.fromJson(new JSONObject(rawContent));
            Log.e(TAG, "Invalid response for intermediate stops: " + br.toString());
        } catch (JSONException e) {
            Log.e(TAG, "Could not parse the reponse for intermediate stops.");
        }
    default:
        Log.e(TAG, "Status code not OK from intermediate stops API, was " + statusCode);
    }

    return trip;
}

From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java

protected void FillData(int nType, String sData) {
    String sCleanData = GetFiresService.removeJsonT(sData);
    try {//ww  w  .  j av  a  2s.c o m
        JSONObject object = new JSONObject(sCleanData);
        String sStatus = object.getString("Status");
        if (sStatus.equals("OK")) {
            JSONArray jsonArray = object.getJSONArray("Result");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONArray jsonSubArray = jsonArray.getJSONArray(i);
                long nID = jsonSubArray.getLong(0);
                String sPtCoord = jsonSubArray.getString(1);
                int nConfidence = jsonSubArray.getInt(2);
                int nPower = jsonSubArray.getInt(3);
                String sURL1 = jsonSubArray.getString(4);
                String sURL2 = jsonSubArray.getString(5);
                String sType = jsonSubArray.getString(6);
                String sPlace = jsonSubArray.getString(7);
                String sDate = jsonSubArray.getString(8);
                String sMap = jsonSubArray.getString(9);

                if (!mmoItems.containsKey(nID)) {
                    ScanexNotificationItem Item = new ScanexNotificationItem(c, nID, sPtCoord, nConfidence,
                            nPower, sURL1, sURL2, sType, sPlace, sDate, sMap, R.drawable.ic_scan);
                    mmoItems.put(Item.GetId(), Item);
                    //notify changes
                    c.onNewNotifictation(GetId(), Item);
                    setHasNews(true);
                }
            }
        } else {
            SendError(object.getString("ErrorInfo"));
        }
    } catch (JSONException e) {
        SendError(e.getLocalizedMessage());
    }

    /*44({
       "Status": "OK",
       "ErrorInfo": "",
       "Result": [[1306601,
       "61.917, 63.090",
       68,
       27.4,
       "\u003ca href=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912\u0027\u003e \u003cimg src=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=100&height=100&bbox=6987987,8766592,7058307,8836912\u0027 width=\u0027{4}\u0027 height=\u0027{5}\u0027 /\u003e\u003c/a\u003e",
       "\u003ca href=\u0027http://fires.kosmosnimki.ru/?x=63.09&y=61.917&z=11&dt=04.10.2013\u0027 target=\"_blank\"\u003eView on the map\u003c/a\u003e",
       "Fire",
       "",
       "\/Date(1380859500000)\/",
       "http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912",
       null]]
    })*/
}