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.blogsentry.BlogsEntryService.java

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

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

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

        _command.put("/blogsentry/get-groups-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 getOrganizationEntries(long organizationId, long displayDate, int status, int max)
        throws Exception {
    JSONObject _command = new JSONObject();

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

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

        _command.put("/blogsentry/get-organization-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.graphhopper.http.GraphHopperWeb.java

@Override
public GHResponse route(GHRequest request) {
    StopWatch sw = new StopWatch().start();
    double took = 0;
    try {//from w  w  w  .  j  av a 2  s .c o m
        String places = "";
        for (GHPoint p : request.getPoints()) {
            places += "point=" + p.lat + "," + p.lon + "&";
        }

        String url = serviceUrl + "?" + places + "&type=json" + "&points_encoded=" + pointsEncoded
                + "&min_path_precision=" + request.getHint("douglas.minprecision", 1) + "&algo="
                + request.getAlgorithm() + "&locale=" + request.getLocale().toString() + "&elevation="
                + withElevation;

        if (!request.getVehicle().isEmpty())
            url += "&vehicle=" + request.getVehicle();

        if (!key.isEmpty())
            url += "&key=" + key;

        String str = downloader.downloadAsString(url);
        JSONObject json = new JSONObject(str);
        GHResponse res = new GHResponse();

        if (json.getJSONObject("info").has("errors")) {
            JSONArray errors = json.getJSONObject("info").getJSONArray("errors");

            for (int i = 0; i < errors.length(); i++) {
                JSONObject error = errors.getJSONObject(i);
                String exClass = error.getString("details");
                String exMessage = error.getString("message");

                if (exClass.equals(UnsupportedOperationException.class.getName())) {
                    res.addError(new UnsupportedOperationException(exMessage));
                } else if (exClass.equals(IllegalStateException.class.getName())) {
                    res.addError(new IllegalStateException(exMessage));
                } else if (exClass.equals(RuntimeException.class.getName())) {
                    res.addError(new RuntimeException(exMessage));
                } else if (exClass.equals(IllegalArgumentException.class.getName())) {
                    res.addError(new IllegalArgumentException(exMessage));
                } else {
                    res.addError(new Exception(exClass + " " + exMessage));
                }
            }

            return res;

        } else {
            took = json.getJSONObject("info").getDouble("took");
            JSONArray paths = json.getJSONArray("paths");
            JSONObject firstPath = paths.getJSONObject(0);
            double distance = firstPath.getDouble("distance");
            int time = firstPath.getInt("time");
            PointList pointList;
            if (pointsEncoded) {
                String pointStr = firstPath.getString("points");
                pointList = WebHelper.decodePolyline(pointStr, 100, withElevation);
            } else {
                JSONArray coords = firstPath.getJSONObject("points").getJSONArray("coordinates");
                pointList = new PointList(coords.length(), withElevation);
                for (int i = 0; i < coords.length(); i++) {
                    JSONArray arr = coords.getJSONArray(i);
                    double lon = arr.getDouble(0);
                    double lat = arr.getDouble(1);
                    if (withElevation)
                        pointList.add(lat, lon, arr.getDouble(2));
                    else
                        pointList.add(lat, lon);
                }
            }

            if (instructions) {
                JSONArray instrArr = firstPath.getJSONArray("instructions");

                InstructionList il = new InstructionList(trMap.getWithFallBack(request.getLocale()));
                for (int instrIndex = 0; instrIndex < instrArr.length(); instrIndex++) {
                    JSONObject jsonObj = instrArr.getJSONObject(instrIndex);
                    double instDist = jsonObj.getDouble("distance");
                    String text = jsonObj.getString("text");
                    long instTime = jsonObj.getLong("time");
                    int sign = jsonObj.getInt("sign");
                    JSONArray iv = jsonObj.getJSONArray("interval");
                    int from = iv.getInt(0);
                    int to = iv.getInt(1);
                    PointList instPL = new PointList(to - from, withElevation);
                    for (int j = from; j <= to; j++) {
                        instPL.add(pointList, j);
                    }

                    // TODO way and payment type
                    Instruction instr = new Instruction(sign, text, InstructionAnnotation.EMPTY, instPL)
                            .setDistance(instDist).setTime(instTime);
                    il.add(instr);
                }
                res.setInstructions(il);
            }
            return res.setPoints(pointList).setDistance(distance).setMillis(time);
        }
    } catch (Exception ex) {
        throw new RuntimeException(
                "Problem while fetching path " + request.getPoints() + ": " + ex.getMessage(), ex);
    } finally {
        logger.debug("Full request took:" + sw.stop().getSeconds() + ", API took:" + took);
    }
}

From source file:com.liferay.mobile.android.v7.mbthread.MBThreadService.java

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

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

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

        _command.put("/mbthread/get-threads", _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.mbthread.MBThreadService.java

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

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

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

        _command.put("/mbthread/get-group-threads", _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.mbthread.MBThreadService.java

public JSONArray getGroupThreads(long groupId, long userId, int status, boolean subscribed, int start, int end)
        throws Exception {
    JSONObject _command = new JSONObject();

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

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

        _command.put("/mbthread/get-group-threads", _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.mbthread.MBThreadService.java

public JSONArray getGroupThreads(long groupId, long userId, long modifiedDate, int status, int start, int end)
        throws Exception {
    JSONObject _command = new JSONObject();

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

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

        _command.put("/mbthread/get-group-threads", _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.mbthread.MBThreadService.java

public JSONArray getGroupThreads(long groupId, long userId, int status, boolean subscribed,
        boolean includeAnonymous, int start, int end) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("groupId", groupId);
        _params.put("userId", userId);
        _params.put("status", status);
        _params.put("subscribed", subscribed);
        _params.put("includeAnonymous", includeAnonymous);
        _params.put("start", start);
        _params.put("end", end);

        _command.put("/mbthread/get-group-threads", _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.jennifer.ui.chart.grid.RadarGrid.java

private void drawRadial(double centerX, double centerY, double x, double y, int count, double unit) {
    Transform group = root.group();
    JSONArray points = new JSONArray();

    points.put(new JSONArray().put(centerX + x).put(centerY + y));

    double startX = x;
    double startY = y;

    for (int i = 0; i < count; i++) {
        JSONObject obj = MathUtil.rotate(startX, startY, unit);

        startX = obj.getDouble("x");
        startY = obj.getDouble("y");

        points.put(new JSONArray().put(centerX + startX).put(centerY + startY));
    }//  www .jav  a  2  s. c  om

    Path path = group
            .path(new JSONObject().put("fill", "none").put("stroke", chart.theme("gridAxisBorderColor"))
                    .put("stroke-width", chart.theme("gridBorderWidth")));

    for (int i = 0, len = points.length(); i < len; i++) {
        JSONArray point = (JSONArray) points.getJSONArray(i);

        if (i == 0) {
            path.MoveTo(point.getDouble(0), point.getDouble(1));
        } else {
            path.LineTo(point.getDouble(0), point.getDouble(1));
        }
    }

    path.LineTo(points.getJSONArray(0).getDouble(0), points.getJSONArray(0).getDouble(1));
}

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void parseJSON(String jsonFile) {
    if (jsonFile != null) {
        // Load all the JSONs with the numbers information
        try {//from   w  w w  .  j  a va2s  .c o m
            JSONObject obj = new JSONObject(loadJSONFromAsset(jsonFile));
            Log.d(TAG, "SHAPE SHADOW JSON FILE " + jsonFile + ": LOADED");

            id = obj.getString("id");

            JSONArray jsonPathData;
            JSONArray jsonShadowData;

            if (!id.equals("5")) {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    try {
                        JSONObject elem = jsonPathData.getJSONObject(i);
                        String type = elem.getString("type");
                        JSONArray data = elem.getJSONArray("data");
                        if (type.equals("move")) {
                            shapePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("line")) {
                            shapePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("bezier")) {
                            shapePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                    (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                    (float) data.getInt(5));
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "JSON ELEM EXCEPTION" + e.getMessage() + "");
                    }
                }
                shapePath.close();

                Random r = new Random();
                r.nextGaussian();

                JSONArray holesContainer = obj.getJSONArray("holes");
                Path holePath = new Path();
                for (int i = 0; i < holesContainer.length(); i++) {
                    JSONObject jsonInside = holesContainer.getJSONObject(i);
                    JSONArray hole = jsonInside.getJSONArray("data");
                    holePath.reset();
                    for (int j = 0; j < hole.length(); j++) {
                        try {
                            JSONObject elem = hole.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                holePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                holePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                holePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON HOLE EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    holePath.close();
                    shapePath.op(holePath, Path.Op.DIFFERENCE);
                }

                pathTransform.reset();
                pathTransform.setScale(scale + 0.04f, scale + 0.04f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX - 0.3f, positionY - 0.3f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                int shadowTmpX;
                int shadowTmpY;

                shadowPaths.clear();
                vertexArray.clear();

                for (int i = 0; i < jsonShadowData.length(); i += 2) {
                    shadowTmpX = jsonShadowData.getInt(i);
                    shadowTmpY = jsonShadowData.getInt(i + 1);
                    addVertex(shadowTmpX, shadowTmpY);
                }
            } else {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    JSONArray cords = jsonPathData.getJSONArray(i);
                    Path chunk = new Path();
                    chunk.reset();
                    for (int j = 0; j < cords.length(); j++) {
                        try {
                            JSONObject elem = cords.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                chunk.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                chunk.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                chunk.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON 5 NUMBER ELEM EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    chunk.close();
                    shapePath.op(chunk, Path.Op.UNION);
                }

                pathTransform.reset();
                pathTransform.setScale(scale, scale);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX, positionY);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                shadowPaths.clear();
                vertexArray.clear();

                int shadowTmpX;
                int shadowTmpY;
                for (int i = 0; i < jsonShadowData.length(); i++) {
                    JSONArray coords = jsonShadowData.getJSONArray(i);
                    for (int j = 0; j < coords.length(); j += 2) {
                        shadowTmpX = coords.getInt(j);
                        shadowTmpY = coords.getInt(j + 1);
                        addVertex((float) shadowTmpX, (float) shadowTmpY);
                    }

                }
            }
        } catch (JSONException e) {
            Log.d(TAG, "JSON ROOT EXCEPTION" + e.getMessage() + "");
        }
    }
}