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:me.timothy.ddd.quests.Quest_LearnAboutGant.java

@SuppressWarnings("unchecked")
@Override/*from  w w w.ja va2 s  .c  o m*/
public JSONObject asObject() {
    JSONObject result = super.asObject();
    result.put("talkCounter", talkCounter);
    return result;
}

From source file:mml.handler.post.MMLPostResourceHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException {
    try {// w  w w . j  a  v  a 2 s  . c  om
        if (ServletFileUpload.isMultipartContent(request)) {
            parseImportParams(request);
            for (int i = 0; i < files.size(); i++) {
                String style = files.get(i);
                JSONObject jDoc = new JSONObject();
                jDoc.put(JSONKeys.BODY, style);
                if (this.author != null)
                    jDoc.put(JSONKeys.AUTHOR, this.author);
                if (this.title != null)
                    jDoc.put(JSONKeys.TITLE, this.title);
                if (this.style != null)
                    jDoc.put(JSONKeys.STYLE, this.style);
                if (this.format != null)
                    jDoc.put(JSONKeys.FORMAT, this.format);
                if (this.section != null)
                    jDoc.put(JSONKeys.SECTION, this.section);
                if (this.version1 != null)
                    jDoc.put(JSONKeys.VERSION1, this.version1);
                Connector.getConnection().putToDb(database, docid, jDoc.toJSONString());
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new MMLException(e);
    }
}

From source file:com.appzone.sim.services.handlers.SendMoServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String address = request.getParameter(KEY_ADDRESS);
    String message = request.getParameter(KEY_MESSAGE);
    String correlator = "" + ((int) (Math.random() * 10000000000000L));

    try {/*from w  ww. j a v a 2 s.c om*/
        String queryString = String.format("version=1.0&address=%s&message=%s&correlator=%s", address,
                URLEncoder.encode(message, "UTF-8"), URLEncoder.encode(correlator, "UTF-8"));

        logger.info("sending MO request as: {}", queryString);
        String response = http.excutePost(application.getUrl(), queryString);
        logger.debug("getting response as: {}", response);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_RESULT, response);
        return json.toJSONString();

    } catch (Exception e) {

        logger.error("Error while sending http request", e);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_ERROR, e.getMessage());
        return json.toJSONString();
    }

}

From source file:com.spleefleague.core.listeners.ChatListener.java

@EventHandler(priority = EventPriority.MONITOR)
public void onChatChannel(ChatChannelMessageEvent event) {
    if (event.getChannel() == ChatChannel.STAFF) {
        ConnectionClient cc = SpleefLeague.getInstance().getConnectionClient();
        if (cc.isEnabled()) {
            event.setCancelled(true);/*from w  w  w  .  j a  v  a  2  s  .c  om*/
            JSONObject send = new JSONObject();
            send.put("message", event.getMessage());
            SpleefLeague.getInstance().getConnectionClient().send("staff", send);
        }
    }
}

From source file:de.tuttas.websockets.ChatServer.java

@OnClose
public void onClose(Session session) {
    Log.d("Session " + session.getId() + " has ended user is " + users.get(session.getId()));
    JSONObject jo = new JSONObject();
    jo.put("from", users.get(session.getId()));
    jo.put("msg", "hat das System verlassen!");
    jo.put("notoast", true);
    send(jo, session);/*from w  ww .  ja v a2 s  . c  om*/
    users.remove(session.getId());
    sessions.remove(session);
}

From source file:mn.EngineForge.module.player.java

public void saveRegisteration() throws IOException {
    JSONObject reg = new JSONObject();
    reg.put("ID", id);
    reg.put("USERNAME", username);
    reg.put("PASSWORD", password);
    reg.put("REG_DATE", null);
    reg.put("LAST_LOGIN", null);
    reg.put("POSITION", null);
    /* JSON ARRAY NOTE/*from w w  w. j av a2s  . c om*/
    JSONArray company = new JSONArray();
    company.add("Compnay: eBay");
    company.add("Compnay: Paypal");
    company.add("Compnay: Google");
    reg.put("Company List", company);
    */
    FileWriter file = new FileWriter(this.path);
    try {
        file.write(reg.toJSONString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        file.flush();
        file.close();
    }
}

From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONHistogramOutputSerializer.java

private JSONObject toJSON(long timestamp, Points.Point point, String unit) throws SerializationException {
    final JSONObject object = new JSONObject();
    object.put("timestamp", timestamp);

    if (!(point.getData() instanceof HistogramRollup)) {
        throw new SerializationException("Unsupported type. HistogramRollup expected.");
    }/* ww w .j av a  2  s  . c  om*/

    HistogramRollup histogramRollup = (HistogramRollup) point.getData();

    final JSONArray hist = new JSONArray();
    for (Bin<SimpleTarget> bin : histogramRollup.getBins()) {
        final JSONObject obj = new JSONObject();
        obj.put("mean", bin.getMean());
        obj.put("count", bin.getCount());
        hist.add(obj);
    }
    object.put("histogram", hist);

    return object;
}

From source file:JavaCloud.Cloud.java

public ArrayList<Token> tokenList() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("login", login);
    object.put("pw_hash", Utils.calcHash(password, seed));

    JSONArray jsontokens = (JSONArray) Utils.request(address, "/user/token/get_list/", object);

    ArrayList<Token> tokens = new ArrayList<Token>();
    for (int i = 0; i < jsontokens.size(); i++) {
        tokens.add(new Token(address, login, password, seed, (JSONObject) jsontokens.get(i)));
    }/*from   w w  w .  j  a  v a 2s.co  m*/

    return tokens;
}

From source file:biz.vnc.zimbra.lighthistoryzimlet.MailhistoryReader.java

public String getRecord(String msgId) {
    JSONObject storejson = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try {//from w w w . j av a 2 s.c o  m
        dbConnection = LocalDB.connect(LocalConfig.get().db_name);
        String query = "SELECT * FROM mail_log_internal WHERE message_id=?" + "ORDER BY logtime ASC";
        PreparedStatement statement = dbConnection.prepareStatement(query);
        statement.setString(1, msgId.trim());
        ResultSet resultSet = statement.executeQuery();
        ZLog.info("biz_vnc_lightweight_history", "Read Message Id" + msgId);
        while (resultSet.next()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("logtime", resultSet.getString("logtime"));
            if (resultSet.getString("from_localpart").equals("-")
                    || resultSet.getString("from_domain").equals("-")) {
                jsonObject.put("from", "-");
            } else {
                jsonObject.put("from",
                        resultSet.getString("from_localpart") + "@" + resultSet.getString("from_domain"));
            }
            if (resultSet.getString("to_localpart").equals("-")
                    || resultSet.getString("to_domain").equals("-")) {
                jsonObject.put("to", "-");
            } else {
                jsonObject.put("to",
                        resultSet.getString("to_localpart") + "@" + resultSet.getString("to_domain"));
            }
            jsonObject.put("moveto", resultSet.getString("foldername"));
            jsonObject.put("event", resultSet.getString("event"));
            jsonArray.add(jsonObject);
        }
        storejson.put("list", jsonArray);
    } catch (Exception e) {
        ZLog.err("mail-history", "getRecord: database query failed", e);
    }
    ZLog.info("biz_vnc_lightweight_history", "Recod Json :: " + storejson.toJSONString());
    return storejson.toJSONString();
}

From source file:com.appzone.sim.services.handlers.MtLogCheckServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String sinceStr = request.getParameter(KEY_SINCE);
    logger.debug("request mt logs since: {}", sinceStr);

    long since = Long.parseLong(sinceStr);

    List<MtMessage> messages = mtMessageRepository.find(since);

    JSONArray list = new JSONArray();

    for (MtMessage mtMessage : messages) {

        String message = mtMessage.getMessage();
        String addresses = JSONValue.toJSONString(mtMessage.getAddresses());
        String receivedDate = "" + mtMessage.getReceivedDate();

        JSONObject json = new JSONObject();
        json.put(JSON_KEY_MESSAGE, message);
        json.put(JSON_KEY_ADDRESSES, JSONValue.parse(addresses));
        json.put(JSON_KEY_RECEIVED_DATE, receivedDate);

        list.add(json);//from w  w w  . j ava2s.com
    }

    logger.debug("returning response: {}", list);

    return list.toJSONString();
}