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:org.kitodo.data.elasticsearch.index.type.BaseType.java

/**
 * Method for adding id to JSONObject./*from w  w w. ja v  a 2 s. co  m*/
 *
 * @param id
 *            of object
 * @return JSONObject
 */
@SuppressWarnings("unchecked")
private JSONObject addIdForRelation(Integer id) {
    JSONObject object = new JSONObject();
    object.put("id", id);
    return object;
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.CircleZone.java

@SuppressWarnings("unchecked")
@Override//from   w ww .  j  ava2 s  .c o  m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "circle");
    o.put("radius", new Double(radius));

    JSONObject c = new JSONObject();
    c.put("lat", new Double(center.getLatitude()));
    c.put("lon", new Double(center.getLongitude()));
    o.put("center", c);

    JSONObject d = new JSONObject();
    d.put("lat", new Double(getDepotPosition().getLatitude()));
    d.put("lon", new Double(getDepotPosition().getLongitude()));
    o.put("depot", c);

    return o.toJSONString();
}

From source file:com.johncroth.histo.logging.LogHistogramWriter.java

@SuppressWarnings("unchecked")
JSONObject convert(LogHistogram x) {//from   www .  java  2 s.  c  om
    JSONObject jo = new JSONObject();
    for (Map.Entry<Integer, Bucket> entry : x.getBucketMap().entrySet()) {
        JSONObject b = new JSONObject();
        b.put(COUNT, entry.getValue().getCount());
        b.put(WEIGHT, entry.getValue().getWeight());
        jo.put(entry.getKey(), b);
    }
    return jo;
}

From source file:com.oic.utils.TestValiadtion.java

public void testMaxLength() {
    JSONObject json = new JSONObject();
    json.put("name", "aaa");
    Validators v = new Validators(json);
    v.add("name", v.maxLength(3));
    assertTrue(v.validate());/*from  w  w  w  .  j  av  a2  s .co m*/
    json.put("name", "aaaa");
    v = new Validators(json);
    v.add("name", v.maxLength(3));
    assertFalse(v.validate());
}

From source file:bhl.pages.handler.PageDesc.java

public JSONObject toJSONObject() {
    JSONObject obj = new JSONObject();
    if (isInteger(n))
        obj.put("n", Integer.parseInt(n));
    else// www . j  a v a  2  s  .c o  m
        obj.put("n", n);
    if (isInteger(id))
        obj.put("id", Integer.parseInt(id));
    else
        obj.put("id", id);
    return obj;
}

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

@Override
protected String doProcess(HttpServletRequest request) {

    String address = request.getParameter(KEY_ADDRESS);
    String sinceStr = request.getParameter(KEY_SINCE);
    logger.debug("request sms messages for: {} since: {}", address, sinceStr);
    long since = Long.parseLong(sinceStr);

    List<Sms> messages = smsRepository.find(address, since);

    JSONArray list = new JSONArray();

    for (Sms sms : messages) {
        JSONObject json = new JSONObject();
        json.put(JSON_KEY_MESSAGE, sms.getMessage());
        json.put(JSON_KEY_RECEIVED_DATE, sms.getReceivedDate());

        list.add(json);//from w  w w.j  av a2  s.co  m
    }

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

    return list.toJSONString();
}

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

@Override
protected String doProcess(HttpServletRequest request) {

    String infoRequest = request.getParameter(KEY_INFO_REQUEST);

    if (infoRequest != null) {
        Application application = Application.getApplication();
        JSONObject json = new JSONObject();
        json.put(JSON_KEY_URL, application.getUrl());
        json.put(JSON_KEY_USERNAME, application.getUsername());
        json.put(JSON_KEY_PASSWORD, application.getPassword());

        return json.toJSONString();
    } else {//from ww w . jav  a2s. co  m
        String url = request.getParameter(KEY_URL);
        String username = request.getParameter(KEY_USERNAME);
        String password = request.getParameter(KEY_PASSWORD);

        logger.info("configuring application with: " + url + " :: {} :: {}", username, password);

        Application.configure(url, username, password);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_RESULT, true);

        return json.toJSONString();
    }
}

From source file:com.demandware.vulnapp.challenge.impl.CookieChallenge.java

@SuppressWarnings("unchecked")
private Cookie generateCookie() {
    JSONObject o = new JSONObject();
    o.put(ACCESS_KEY, "false");
    String value = new String(Base64.encodeBase64(o.toJSONString().getBytes()));
    Cookie c = new Cookie(COOKIE_NAME, value);
    c.setMaxAge(MAX_AGE);//from w w w. java 2  s .  com
    c.setPath("/");
    return c;
}

From source file:mikolaj.torrent.communication.server.actions.Shares.java

public Result perform(HashMap<String, String> paramsMap) {
    File[] files = new File(Service.getInstance().getServer().getShareDirectory()).listFiles();

    List<JSONObject> fileCollection = new ArrayList<>();

    try {/*  ww w.ja  v  a2  s .  c  o m*/
        for (File file : files) {
            if (!file.isDirectory()) {
                JSONObject fileObject = new JSONObject();
                fileObject.put("fileName", file.getName().replace(" ", "__"));
                fileObject.put("checkSum", Checksum.getMD5Checksum(file.getAbsolutePath()));
                fileCollection.add(fileObject);
            }
        }
    } catch (Exception ex) {
        System.out
                .println("Problem with share you files list, check your permission to application. Exiting...");
        System.exit(1);
    }

    Result result = new Result();
    result.saveJson(fileCollection);

    return result;
}

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

@Override
protected String doProcess(HttpServletRequest request) {

    String phoneNo = request.getParameter(KEY_PHONE_NO);
    // converting to md5
    phoneNo = getMD5(phoneNo);//from www.j ava 2s.co  m

    Phone phone = new Phone(phoneNo);

    logger.debug("adding a new phone: {}", phoneNo);
    phoneRepository.add(phone);

    JSONObject json = new JSONObject();
    json.put(JSON_KEY_MD5_PHONE_NO, phoneNo);

    return json.toJSONString();
}