Example usage for org.json.simple JSONObject put

List of usage examples for org.json.simple JSONObject put

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.oic.event.CheckDuplication.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "duplication");
    Validators v = new Validators(json);
    v.add("username", v.required(), v.maxLength(24));
    if (!v.validate()) {
        responseJSON.put("result", 2);
        return;// w  w w .j a v  a2  s. c  o m
    } else {
        //??
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            String sql = "SELECT name FROM user WHERE name = ?";
            con = DatabaseConnection.getConnection();
            ps = con.prepareStatement(sql);
            ps.setString(1, json.get("username").toString());
            rs = ps.executeQuery();
            if (rs.next()) {//?
                responseJSON.put("result", 1);
            } else {//
                webSocket.userRegister();//
                responseJSON.put("result", 0);
            }
        } catch (Exception e) {
            responseJSON.put("result", 2);
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (Exception e1) {
            }
            try {
                ps.close();
            } catch (Exception e1) {
            }
        }
    }
    webSocket.sendJson(responseJSON);
}

From source file:co.mcme.animations.triggers.ShapeInteractTrigger.java

@Override
public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    JSONObject data = new JSONObject();
    data.put("frame", frame);
    result.put("shape_interaction", data);
    return result;
}

From source file:io.personium.client.LinkManager.java

/**
 * This method is used to create a link between two cell control objects.
 * @param cx ILinkageResource//from w  ww  . j  a va  2  s.  c  o  m
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public void link(ILinkageResource cx) throws DaoException {
    String uri = getLinkUrl(cx);

    String linksUri = null;
    if (this.accessor.isBatchMode()) {
        linksUri = ((BatchLinksEntity) this.context).getCollectionUrl() + cx.getODataLink();
    } else {
        linksUri = cx.getODataLink();
    }

    JSONObject body = new JSONObject();
    body.put("uri", linksUri);

    IRestAdapter rest = RestAdapterFactory.create(accessor);
    rest.post(uri, body.toJSONString(), RestAdapter.CONTENT_TYPE_JSON);
}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONObject newColumn(String label, String type) {
    JSONObject col = new JSONObject();
    col.put("label", label);
    col.put("type", type);
    return col;/*from www. ja  v a  2  s .  co  m*/
}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONObject newDataCell(double value) {
    JSONObject cell = new JSONObject();
    cell.put("v", value);
    return cell;/*  www.j  a  va 2  s.c  o  m*/
}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONObject newTsCell(long ts) {
    JSONObject cell = new JSONObject();
    cell.put("v", ts * 1000);
    return cell;/*from www  .j  a v  a  2s .c  o m*/
}

From source file:com.mobicage.rogerthat.form.AbstractSliderWidget.java

@Override
@SuppressWarnings("unchecked")
public JSONObject toJSONObject() {
    JSONObject result = new JSONObject();
    result.put("min", min);
    result.put("max", max);
    result.put("step", step);
    result.put("unit", unit);
    result.put("precision", precision);
    return result;
}

From source file:de.minestar.sixteenblocks.Threads.JSONThread.java

@SuppressWarnings("unchecked")
@Override/*ww w  . j av a2 s .  c o m*/
public void run() {
    // Create sync thread to use notthreadsafe methods
    Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {

        @Override
        public void run() {
            BufferedWriter bWriter = null;
            try {
                JSONObject json = new JSONObject();
                json.put("ConnectedUsers", Bukkit.getOnlinePlayers().length);
                json.put("Skins", aManager.getUsedAreaCount());
                json.put("Slots", Core.getAllowedMaxPlayer());
                bWriter = new BufferedWriter(new FileWriter(JSONFile));
                bWriter.write(json.toJSONString());
                bWriter.flush();
                bWriter.close();
            } catch (Exception e) {
                ConsoleUtils.printException(e, Core.NAME, "Can't save JSON");
            } finally {
                try {
                    if (bWriter != null)
                        bWriter.close();
                } catch (Exception e2) {
                    // IGNORE SECOND EXCEPTION
                }
            }
        }
    });

}

From source file:me.timothy.ddd.quests.BasicQuest.java

@SuppressWarnings("unchecked")
@Override//from   w  w w . ja v a 2  s . c  o  m
public JSONObject asObject() {
    JSONObject result = new JSONObject();
    result.put("class", getClass().getName());
    return result;
}

From source file:com.conwet.silbops.msg.AdvertiseMsg.java

@Override
@SuppressWarnings("unchecked")
public JSONObject getPayloadAsJSON() {

    JSONObject json = new JSONObject();
    json.put("advertise", advertise.toJSON());
    json.put("context", context.toJSON());
    return json;/*from w  ww . j a  va  2 s . c o  m*/
}