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.wso2.rfid.apicalls.APICall.java

public static void userCheckin(String deviceID, String rfid, String url, String consumerKey,
        String consumerSecret) throws UserCheckinException {
    //        String url = "https://gateway.apicloud.cloudpreview.wso2.com:8243/t/indikas.com/wso2coniot/1.0.0/conferences/2/userCheckIn";
    Token token = getToken(consumerKey, consumerSecret);
    if (token != null) {
        HttpClient httpClient = new HttpClient();
        JSONObject json = new JSONObject();
        json.put("uuid", deviceID);
        json.put("rfid", rfid);
        try {//from   w  w  w.j  a  v a 2s  . c  o m
            HttpResponse httpResponse = httpClient.doPost(url, "Bearer " + token.getAccessToken(),
                    json.toJSONString(), "application/json");
            int statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode != 200) {
                throw new UserCheckinException(
                        "User checkin failed. HTTP Status Code:" + statusCode + ", RFID: " + rfid + ", CK="
                                + consumerKey + ", CS=" + consumerSecret + ", URL=" + url);
            }
        } catch (IOException e) {
            log.error("", e);
        }
    }
}

From source file:net.amigocraft.mpt.command.AddRepositoryCommand.java

@SuppressWarnings("unchecked")
public static String addRepository(String path) throws MPTException {
    if (Thread.currentThread().getId() == Main.mainThreadId)
        throw new MPTException(ERROR_COLOR + "Repositories may not be added from the main thread!");
    try {/* w w w . ja va2s.c o  m*/
        JSONObject json = MiscUtil.getRemoteIndex(path);
        String id = json.get("id").toString().toLowerCase(); // get ID from remote
        File store = new File(Main.plugin.getDataFolder(), "repositories.json");
        if (!store.exists())
            Main.initializeRepoStore(store); // gotta initialize it before using it
        lockStores();
        JSONObject repoElement = new JSONObject(); // create a new JSON object
        repoElement.put("url", path); // set the repo URL
        ((JSONObject) Main.repoStore.get("repositories")).put(id, repoElement);
        writeRepositoryStore();
        unlockStores();
        return id;
        // apt-get doesn't fetch packages when a repo is added, so I'm following that precedent
    } catch (IOException ex) {
        unlockStores();
        throw new MPTException(ERROR_COLOR + "Failed to add repository to local " + "store!");
    }
}

From source file:be.fedict.eid.applet.service.JSONServlet.java

private static JSONObject createCertJSONObject(X509Certificate certificate, SimpleDateFormat simpleDateFormat)
        throws CertificateEncodingException, IOException {
    JSONObject certJSONObject = new JSONObject();
    certJSONObject.put("subject", certificate.getSubjectX500Principal().toString());
    certJSONObject.put("issuer", certificate.getIssuerX500Principal().toString());
    certJSONObject.put("serialNumber", certificate.getSerialNumber().toString());
    certJSONObject.put("notBefore", certificate.getNotBefore().toString());
    certJSONObject.put("notAfter", certificate.getNotAfter().toString());
    certJSONObject.put("signatureAlgo", certificate.getSigAlgName());
    certJSONObject.put("thumbprint", DigestUtils.shaHex(certificate.getEncoded()));
    certJSONObject.put("details", certificate.toString());
    certJSONObject.put("pem", toPem(certificate));

    return certJSONObject;
}

From source file:net.jselby.pc.player.ChatMessage.java

/**
 * Converts a string to a basic ChatMessage
 *
 * @param message The String message//from   w  ww  .ja  va  2 s.  c om
 * @return A Chat message
 */
public static ChatMessage convertToJson(String message) {
    JSONObject obj = new JSONObject();

    // Parse message, looking for colors etc.
    ArrayList<JSONObject> objects = new ArrayList<JSONObject>();

    ChatColor color = ChatColor.WHITE;
    String currentMessage = "";

    boolean nextByteAsColor = false;

    for (char bytes : message.toCharArray()) {
        if (nextByteAsColor) {
            color = ChatColor.getByChar(bytes);
            nextByteAsColor = false;
            continue;
        }
        if (bytes == ChatColor.COLOR_CHAR) { // Special color symbol
            if (currentMessage.length() > 0) {
                JSONObject currentMessageAsJSON = new JSONObject();
                currentMessageAsJSON.put("text", currentMessage);
                currentMessageAsJSON.put("color", color.name().toLowerCase());
                objects.add(currentMessageAsJSON);
            }
            color = ChatColor.WHITE;
            currentMessage = "";
            nextByteAsColor = true;
        } else {
            currentMessage += bytes;
        }
    }

    if (currentMessage.length() > 0) {
        JSONObject rest = new JSONObject();
        rest.put("text", currentMessage);
        rest.put("color", color.name().toLowerCase());
        objects.add(rest);
    }

    JSONArray array = new JSONArray();

    for (JSONObject jsonObject : objects) {
        array.add(jsonObject);
    }

    obj.put("extra", array);
    obj.put("text", "");

    return new ChatMessage(obj);
}

From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java

public static void saveList(Collection<GraphOperation> ops, File f, Map<String, Double> queryNodes)
        throws IOException {
    FileWriter wr = new FileWriter(f);
    JSONArray arr = new JSONArray();
    for (GraphOperation op : ops) {
        JSONObject obj = op.toJSON();//  ww  w  .java 2 s  . c  o m
        JSONObject mark = new JSONObject();
        mark.put("class", op.getClass().getName());
        mark.put("object", obj);
        arr.add(mark);
    }

    JSONArray noi = new JSONArray();
    for (String z : queryNodes.keySet()) {
        JSONObject jo = new JSONObject();
        jo.put("node", z);
        Double val = queryNodes.get(z);
        jo.put("value", val);
        noi.add(jo);
    }
    arr.add(noi);

    arr.writeJSONString(wr);
    wr.close();
}

From source file:cpd3314.buildit12.CPD3314BuildIt12.java

/**
 * Build a sample method that saves a handful of car instances as Serialized
 * objects, and as JSON objects.//w  ww. j  av  a2 s . co  m
 */
public static void doBuildIt2Output() {
    Car[] cars = { new Car("Honda", "Civic", 2001), new Car("Buick", "LeSabre", 2003),
            new Car("Toyota", "Camry", 2005) };

    // Saves as Serialized Objects
    try {
        FileOutputStream objFile = new FileOutputStream("cars.obj");
        ObjectOutputStream objStream = new ObjectOutputStream(objFile);

        for (Car car : cars) {
            objStream.writeObject(car);
        }

        objStream.close();
        objFile.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Saves as JSONObject
    try {
        PrintWriter jsonStream = new PrintWriter("cars.json");

        JSONArray arr = new JSONArray();
        for (Car car : cars) {
            arr.add(car.toJSON());
        }

        JSONObject json = new JSONObject();
        json.put("cars", arr);

        jsonStream.println(json.toJSONString());

        jsonStream.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static JSONObject createService(String id, String className) {

    JSONObject service = new JSONObject();
    service.put(Service.NAME, id);
    service.put(Service.CLASS, className);
    return service;

}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static String createScalar(String elementName, String viewPath, String method) {

    JSONObject data = new JSONObject();
    data.put("elementName", elementName);
    data.put("viewPath", viewPath);
    data.put("method", method);

    JSONObject header = new JSONObject();
    header.put("type", "scalar");
    header.put("data", data);

    return header.toString();

}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static String createReference(String elementName, String qualifier, String viewPath, String method) {

    JSONObject data = new JSONObject();
    data.put("elementName", elementName);
    data.put("qualifier", qualifier);
    data.put("viewPath", viewPath);
    data.put("method", method);

    JSONObject header = new JSONObject();
    header.put("type", "reference");
    header.put("data", data);

    return header.toString();

}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static String createDefaultSyntheticServices() {

    JSONArray data = new JSONArray();

    JSONObject request = new JSONObject();
    request.put(Service.NAME, "request");
    request.put(Service.CLASS, "Symfony\\Component\\HttpFoundation\\Request");

    data.add(request);//from   w ww. j a va 2s.  co m
    return data.toString();

}