Example usage for org.json JSONObject JSONObject

List of usage examples for org.json JSONObject JSONObject

Introduction

In this page you can find the example usage for org.json JSONObject JSONObject.

Prototype

public JSONObject() 

Source Link

Document

Construct an empty JSONObject.

Usage

From source file:com.liferay.mobile.android.v7.announcementsentry.AnnouncementsEntryService.java

public void deleteEntry(long entryId) throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("entryId", entryId);

        _command.put("/announcementsentry/delete-entry", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    session.invoke(_command);
}

From source file:com.liferay.mobile.android.v7.announcementsentry.AnnouncementsEntryService.java

public JSONObject updateEntry(long entryId, String title, String content, String url, String type,
        int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour,
        int displayDateMinute, boolean displayImmediately, int expirationDateMonth, int expirationDateDay,
        int expirationDateYear, int expirationDateHour, int expirationDateMinute, int priority)
        throws Exception {
    JSONObject _command = new JSONObject();

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

        _params.put("entryId", entryId);
        _params.put("title", checkNull(title));
        _params.put("content", checkNull(content));
        _params.put("url", checkNull(url));
        _params.put("type", checkNull(type));
        _params.put("displayDateMonth", displayDateMonth);
        _params.put("displayDateDay", displayDateDay);
        _params.put("displayDateYear", displayDateYear);
        _params.put("displayDateHour", displayDateHour);
        _params.put("displayDateMinute", displayDateMinute);
        _params.put("displayImmediately", displayImmediately);
        _params.put("expirationDateMonth", expirationDateMonth);
        _params.put("expirationDateDay", expirationDateDay);
        _params.put("expirationDateYear", expirationDateYear);
        _params.put("expirationDateHour", expirationDateHour);
        _params.put("expirationDateMinute", expirationDateMinute);
        _params.put("priority", priority);

        _command.put("/announcementsentry/update-entry", _params);
    } catch (JSONException _je) {
        throw new Exception(_je);
    }

    JSONArray _result = session.invoke(_command);

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

    return _result.getJSONObject(0);
}

From source file:net.straylightlabs.archivo.net.MindCommandRecordingFolderItemSearch.java

private static JSONArray buildTemplate() {
    JSONArray templates = new JSONArray();
    JSONObject template;/*ww w.  ja  va 2 s. c o m*/

    // Only get the recording ID
    template = new JSONObject();
    template.put(TYPE, "responseTemplate");
    template.put(FIELD_NAME, Collections.singletonList("childRecordingId"));
    template.put(TYPE_NAME, "recordingFolderItem");
    templates.put(template);

    return templates;
}

From source file:com.graphhopper.http.InfoServlet.java

void writeInfos(HttpServletRequest req, HttpServletResponse res) throws Exception {
    BBox bb = hopper.getGraph().getBounds();
    List<Double> list = new ArrayList<Double>(4);
    list.add(bb.minLon);//from  w ww . jav  a  2s .c o m
    list.add(bb.minLat);
    list.add(bb.maxLon);
    list.add(bb.maxLat);

    JSONObject json = new JSONObject();
    json.put("bbox", list);

    String[] vehicles = hopper.getGraph().getEncodingManager().toString().split(",");
    json.put("supported_vehicles", vehicles);
    JSONObject features = new JSONObject();
    for (String v : vehicles) {
        JSONObject perVehicleJson = new JSONObject();
        perVehicleJson.put("elevation", hopper.hasElevation());
        features.put(v, perVehicleJson);
    }
    json.put("features", features);

    json.put("version", Constants.VERSION);
    json.put("build_date", Constants.BUILD_DATE);

    StorableProperties props = hopper.getGraph().getProperties();
    json.put("import_date", props.get("osmreader.import.date"));

    if (!Helper.isEmpty(props.get("prepare.date")))
        json.put("prepare_date", props.get("prepare.date"));

    writeJson(req, res, json);
}

From source file:com.shampan.services.SearchService.java

/**
 * This method will return users/*from w w  w  .  jav  a  2s  .c o  m*/
 *
 * @param requestPatten, request String
 * @return users
 */
public static String getSearchResult(String searchValue, int offset, int limit) {
    JSONObject searchResult = new JSONObject();
    searchResult.put("userList", searchModel.getUsers(searchValue, offset, limit));
    searchResult.put("pageList", searchModel.getPages(searchValue, offset, limit));
    return searchResult.toString();
}

From source file:edu.mit.scratch.ScratchProject.java

public boolean comment(final ScratchSession session, final String comment) throws ScratchProjectException {
    final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

    final CookieStore cookieStore = new BasicCookieStore();
    final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en");
    final BasicClientCookie sessid = new BasicClientCookie("scratchsessionsid", session.getSessionID());
    final BasicClientCookie token = new BasicClientCookie("scratchcsrftoken", session.getCSRFToken());
    final BasicClientCookie debug = new BasicClientCookie("DEBUG", "true");
    lang.setDomain(".scratch.mit.edu");
    lang.setPath("/");
    sessid.setDomain(".scratch.mit.edu");
    sessid.setPath("/");
    token.setDomain(".scratch.mit.edu");
    token.setPath("/");
    debug.setDomain(".scratch.mit.edu");
    debug.setPath("/");
    cookieStore.addCookie(lang);/*from www .  j av a 2s  .  c o  m*/
    cookieStore.addCookie(sessid);
    cookieStore.addCookie(token);
    cookieStore.addCookie(debug);

    final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
            .setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64)"
                    + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/" + "537.36")
            .setDefaultCookieStore(cookieStore).build();
    CloseableHttpResponse resp;

    final JSONObject obj = new JSONObject();
    obj.put("content", comment);
    obj.put("parent_id", "");
    obj.put("commentee_id", "");
    final String strData = obj.toString();

    HttpUriRequest update = null;
    try {
        update = RequestBuilder.post()
                .setUri("https://scratch.mit.edu/site-api/comments/project/" + this.getProjectID() + "/add/")
                .addHeader("Accept",
                        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                .addHeader("Referer", "https://scratch.mit.edu/projects/" + this.getProjectID() + "/")
                .addHeader("Origin", "https://scratch.mit.edu/")
                .addHeader("Accept-Encoding", "gzip, deflate, sdch")
                .addHeader("Accept-Language", "en-US,en;q=0.8").addHeader("Content-Type", "application/json")
                .addHeader("X-Requested-With", "XMLHttpRequest")
                .addHeader("Cookie",
                        "scratchsessionsid=" + session.getSessionID() + "; scratchcsrftoken="
                                + session.getCSRFToken())
                .addHeader("X-CSRFToken", session.getCSRFToken()).setEntity(new StringEntity(strData)).build();
    } catch (final UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    try {
        resp = httpClient.execute(update);
        System.out.println("cmntadd:" + resp.getStatusLine());
        final BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

        final StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null)
            result.append(line);
        System.out.println("cmtline:" + result.toString());
    } catch (final IOException e) {
        e.printStackTrace();
        throw new ScratchProjectException();
    }

    BufferedReader rd;
    try {
        rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    } catch (UnsupportedOperationException | IOException e) {
        e.printStackTrace();
        throw new ScratchProjectException();
    }

    return false;
}

From source file:com.jennifer.ui.chart.grid.RuleGrid.java

@Override
protected void drawTop(Transform root) {
    int width = chart.area("width");
    int height = chart.area("height");
    double half_width = (double) width / 2;
    double half_height = (double) height / 2;

    double centerPosition = center ? half_height : 0;

    JSONObject o = new JSONObject();
    o.put("y1", centerPosition);
    o.put("y2", centerPosition);
    o.put("x2", chart.area("width"));
    root.append(this.axisLine(o));

    double min = this.scale.min();

    for (int i = 0, len = ticks.length(); i < len; i++) {
        boolean isZero = (ticks.getDouble(i) == 0);

        Transform axis = root.group().translate(this.values.getDouble(i), centerPosition);

        JSONObject lineOpt = new JSONObject();
        lineOpt.put("y1", center ? -bar : 0);
        lineOpt.put("y2", bar);
        lineOpt.put("stroke", chart.theme("gridAxisBorderColor"));
        lineOpt.put("stroke-width", chart.theme("gridBorderWidth"));

        axis.append(line(lineOpt));//  ww  w  . j  a  v a 2 s .  com

        if (!isZero || (isZero && !hideZero)) {
            JSONObject textOpt = new JSONObject();
            textOpt.put("x", 0);
            textOpt.put("y", bar * 2 + 4);
            textOpt.put("text-anchor", "middle");
            textOpt.put("fill", chart.theme("gridFontColor"));

            axis.append(chart.text(textOpt, getFormatString(ticks.get(i))));
        }

    }
}

From source file:com.jennifer.ui.chart.grid.RuleGrid.java

@Override
protected void drawBottom(Transform root) {
    int width = chart.area("width");
    int height = chart.area("height");
    double half_width = (double) width / 2;
    double half_height = (double) height / 2;

    double centerPosition = center ? -half_height : 0;

    JSONObject o = new JSONObject();
    o.put("y1", centerPosition);
    o.put("y2", centerPosition);
    o.put("x2", chart.area("width"));
    root.append(this.axisLine(o));

    double min = this.scale.min();

    for (int i = 0, len = ticks.length(); i < len; i++) {
        boolean isZero = (ticks.getDouble(i) == 0);

        Transform axis = root.group().translate(this.values.getDouble(i), centerPosition);

        JSONObject lineOpt = new JSONObject();
        lineOpt.put("y1", center ? -bar : 0);
        lineOpt.put("y2", center ? bar : -bar);
        lineOpt.put("stroke", chart.theme("gridAxisBorderColor"));
        lineOpt.put("stroke-width", chart.theme("gridBorderWidth"));

        axis.append(line(lineOpt));/*w  w  w . j a  v  a2 s.c  om*/

        if (!isZero || (isZero && !hideZero)) {
            JSONObject textOpt = new JSONObject();
            textOpt.put("x", 0);
            textOpt.put("y", -bar * 2);
            textOpt.put("text-anchor", "middle");
            textOpt.put("fill", chart.theme("gridFontColor"));

            axis.append(chart.text(textOpt, getFormatString(ticks.get(i))));
        }

    }
}

From source file:com.jennifer.ui.chart.grid.RuleGrid.java

@Override
protected void drawLeft(Transform root) {
    int width = chart.area("width");
    int height = chart.area("height");
    double half_width = (double) width / 2;
    double half_height = (double) height / 2;

    double centerPosition = center ? half_width : 0;

    JSONObject o = new JSONObject();
    o.put("x1", centerPosition);
    o.put("x2", centerPosition);
    o.put("y2", chart.area("height"));
    root.append(this.axisLine(o));

    double min = this.scale.min();

    for (int i = 0, len = ticks.length(); i < len; i++) {
        boolean isZero = (ticks.getDouble(i) == 0);

        Transform axis = root.group().translate(centerPosition, this.values.getDouble(i));

        JSONObject lineOpt = new JSONObject();
        lineOpt.put("x1", center ? -bar : 0);
        lineOpt.put("x2", bar);
        lineOpt.put("stroke", chart.theme("gridAxisBorderColor"));
        lineOpt.put("stroke-width", chart.theme("gridBorderWidth"));

        axis.append(line(lineOpt));//www  .j  av a2 s .co  m

        if (!isZero || (isZero && !hideZero)) {
            JSONObject textOpt = new JSONObject();
            textOpt.put("x", 2 * bar);
            textOpt.put("y", bar - 2);
            textOpt.put("text-anchor", "start");
            textOpt.put("fill", chart.theme("gridFontColor"));

            axis.append(chart.text(textOpt, getFormatString(ticks.get(i))));
        }

    }
}

From source file:com.jennifer.ui.chart.grid.RuleGrid.java

@Override
protected void drawRight(Transform root) {
    int width = chart.area("width");
    int height = chart.area("height");
    double half_width = (double) width / 2;
    double half_height = (double) height / 2;

    double centerPosition = center ? -half_width : 0;

    JSONObject o = new JSONObject();
    o.put("x1", centerPosition);
    o.put("x2", centerPosition);
    o.put("y2", chart.area("width"));
    root.append(this.axisLine(o));

    double min = this.scale.min();

    for (int i = 0, len = ticks.length(); i < len; i++) {
        boolean isZero = (ticks.getDouble(i) == 0);

        Transform axis = root.group().translate(centerPosition, this.values.getDouble(i));

        JSONObject lineOpt = new JSONObject();
        lineOpt.put("x1", center ? -bar : 0);
        lineOpt.put("x2", center ? bar : -bar);
        lineOpt.put("stroke", chart.theme("gridAxisBorderColor"));
        lineOpt.put("stroke-width", chart.theme("gridBorderWidth"));

        axis.append(line(lineOpt));/*from  w w w .j  a  v  a2  s.  c om*/

        if (!isZero || (isZero && !hideZero)) {
            JSONObject textOpt = new JSONObject();
            textOpt.put("x", -bar - 4);
            textOpt.put("y", bar - 2);
            textOpt.put("text-anchor", "middle");
            textOpt.put("fill", chart.theme("gridFontColor"));

            axis.append(chart.text(textOpt, getFormatString(ticks.get(i))));
        }

    }

}