Example usage for org.json.simple JSONObject toJSONString

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

Introduction

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

Prototype

public String toJSONString() 

Source Link

Usage

From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?./* w w w  .j a v a2  s.c o m*/
 * @param token 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param body 
 * @return ?
 */
public static DcResponse updateWithToken(String token, String cell, String box, String collection,
        String srcComplexTypePropertyName, String srcComplexTypeName, JSONObject body) {

    // 
    DcRequest req = DcRequest.put(UrlUtils.complexTypeProperty(cell, box, collection,
            srcComplexTypePropertyName, srcComplexTypeName));
    req.header(HttpHeaders.AUTHORIZATION, OAuth2Helper.Scheme.BEARER + " " + token);
    req.header(HttpHeaders.IF_MATCH, "*");
    req.addStringBody(body.toJSONString());

    // 
    return AbstractCase.request(req);

}

From source file:model.Post_store.java

public static void update_post(String title, String content, List<String> comments, List<String> UA_comments,
        int id) {
    JSONObject obj = new JSONObject();
    obj.put("title", title);
    obj.put("content", content);

    JSONArray Jcomments = new JSONArray();
    for (String i : comments) {
        Jcomments.add(i);/*from w ww .j  a v  a2s.  co  m*/
    }
    obj.put("comments", comments);

    JSONArray JUA_comments = new JSONArray();
    for (String i : UA_comments) {
        JUA_comments.add(i);
    }
    obj.put("UA_comments", UA_comments);

    try (FileWriter file = new FileWriter(root + "posts/" + id + ".json");) {
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        System.out.println(e);
    }

    //System.out.print(obj);
}

From source file:com.iitb.cse.Utils.java

/**
 * genetated and returns the String in Json format. String contains
 * information that the experiment has been stopped by experimenter This
 * string is later sent to filtered devices.
 *//*w  w  w  .j a  va  2  s.c o  m*/
@SuppressWarnings("unchecked")
static String getStopSignalJson() {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, Constants.stopExperiment);
    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}

From source file:com.iitb.cse.Utils.java

/**
 * genetated and returns the String in Json format. String contains
 * information that all the registration has been cleared by experimenter
 * This string is later sent to filtered devices.
 *//*  w ww .ja va 2s .  co  m*/
@SuppressWarnings("unchecked")
static String getClearRegistrationJson() {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, Constants.clearRegistration);
    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}

From source file:com.iitb.cse.Utils.java

/**
 * genetated and returns the String in Json format. String contains
 * information that the experimentee wants to ping the devices and refresh
 * the list of registered devices This string is later sent to registered
 * devices.//from  w w w  . j a  v  a  2s. co m
 */
@SuppressWarnings("unchecked")
static String getRefreshRegistrationJson() {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, Constants.refreshRegistration);
    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}

From source file:io.personium.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java

/**
 * ComplexTypeProperty?./*w  ww .  ja v  a2 s  .  c o m*/
 * @param token 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcComplexTypePropertyName ?ComplexTypeProperty??
 * @param srcComplexTypeName ?ComplexType??
 * @param body 
 * @return ?
 */
public static PersoniumResponse updateWithToken(String token, String cell, String box, String collection,
        String srcComplexTypePropertyName, String srcComplexTypeName, JSONObject body) {

    // 
    PersoniumRequest req = PersoniumRequest.put(UrlUtils.complexTypeProperty(cell, box, collection,
            srcComplexTypePropertyName, srcComplexTypeName));
    req.header(HttpHeaders.AUTHORIZATION, OAuth2Helper.Scheme.BEARER + " " + token);
    req.header(HttpHeaders.IF_MATCH, "*");
    req.addStringBody(body.toJSONString());

    // 
    return AbstractCase.request(req);

}

From source file:it.polimi.logging.LogMessageUtils.java

/**
 * /*from   w w w.j a va  2s  .  co  m*/
 * Costruisce un messaggio di log rappresentante un messaggio ricevuto da un device
 * 
 * @param id
 * @param sender
 * @param type
 * @param logType
 * @param eventType
 * @param timestamp
 * @return
 */
public static String buildMessageReceivedLog(String id, String sender, Type type, MessageType eventType,
        String topic_reply, JSONObject status, long timestamp) {

    JSONObject msg = new JSONObject();
    msg.put(JsonStrings.LOG_ID, id);
    msg.put(JsonStrings.SENDER, sender);
    msg.put(JsonStrings.ENTITY_TYPE, type.name());
    msg.put(JsonStrings.LOG_TYPE, LogType.REC_MSG.name());
    msg.put(JsonStrings.EVENT_TYPE, eventType.name());

    if (eventType.equals(MessageType.SYNC_RESP))
        msg.put(JsonStrings.TOPIC_REPLY, topic_reply);

    msg.put(JsonStrings.STATUS, status);
    msg.put(JsonStrings.TIMESTAMP, timestamp);

    return msg.toJSONString();

}

From source file:com.fujitsu.dc.test.utils.RoleUtils.java

/**
 * NP?Role??.//from  www  .  j a v a  2s .  co m
 * @param cellName ??
 * @param token 
 * @param srcEntityName ???
 * @param srcEntityKeyString ?"Name='xxx'"
 * @param roleName ??
 * @param code ?
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaNP(final String cellName, final String token, final String srcEntityName,
        final String srcEntityKeyString, final String roleName, final int code) {
    JSONObject body = new JSONObject();
    body.put("Name", roleName);

    return Http.request("cell/createNPWithoutQuote.txt").with("method", HttpMethod.POST)
            .with("token", "Bearer " + token).with("cell", cellName).with("entityType", srcEntityName)
            .with("id", srcEntityKeyString).with("navPropName", "_Role")
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("body", body.toJSONString()).returns().statusCode(code);
}

From source file:it.polimi.logging.LogMessageUtils.java

/**
 * //  w w w .j a  v  a  2s.  c  o m
 * Costruisce un messaggio di log per rappresentare i messaggi inviati sulla rete da un device
 * 
 * @param id
 * @param sender
 * @param type
 * @param logType
 * @param eventType - rappresenta l'evento che verr eventualmente scatenato, quindi il {@link MessageType}
 * @param valid - ha senso solo per i messaggi di tipo {@link MessageType#CHECK_OUT}
 * @param timestamp
 * @return
 */
public static String buildMessageSentLog(String id, String sender, Type type, MessageType eventType,
        String topic_reply, boolean valid, long timestamp) {

    JSONObject msg = new JSONObject();
    msg.put(JsonStrings.LOG_ID, id);
    msg.put(JsonStrings.SENDER, sender);
    msg.put(JsonStrings.ENTITY_TYPE, type.name());
    msg.put(JsonStrings.LOG_TYPE, LogType.SENT_MSG.name());
    msg.put(JsonStrings.EVENT_TYPE, eventType.name());

    if (eventType.equals(MessageType.SYNC_REQ))
        msg.put(JsonStrings.TOPIC_REPLY, topic_reply);

    if (eventType.equals(MessageType.CHECK_OUT))
        msg.put(JsonStrings.VALID, valid);

    msg.put(JsonStrings.TIMESTAMP, timestamp);

    return msg.toJSONString();

}

From source file:com.iitb.cse.Utils.java

@SuppressWarnings("unchecked")
static String getHeartBeatDuration(String duration) {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, "hbDuration");
    obj.put("heartbeat_duration", duration);
    obj.put("hbDuration", duration);

    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}