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:JavaCloud.Cloud.java

public Cloud(String address, String login, String password) throws CoreException {
    this.address = address;
    this.login = login;
    this.password = password;
    JSONObject object = new JSONObject();
    object.put("login", login);

    this.seed = ((JSONObject) Utils.request(address, "/user/user/get_seed/", object)).get("seed").toString();
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Picture.java

@SuppressWarnings("unchecked")
@Override//from  w  ww  . jav  a2s .c  o m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_PHOTO);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", getFilename());
    }
    return o.toJSONString();
}

From source file:com.flaptor.indextank.api.resources.Autocomplete.java

/**
 * @see java.lang.Runnable#run()//from  w w w  .  ja va2  s.c om
 */
public void run() {
    IndexEngineApi api = (IndexEngineApi) ctx().getAttribute("api");
    HttpServletResponse res = res();

    String characterEncoding = api.getCharacterEncoding();
    try {
        req().setCharacterEncoding(characterEncoding);
        res.setCharacterEncoding(characterEncoding);
        res.setContentType("application/json");
    } catch (UnsupportedEncodingException ignored) {
    }

    String query = params("query");
    String field = params("field");
    String callback = params("callback");

    if (field == null || field.isEmpty()) {
        field = "text";
    }

    List<String> complete = api.complete(query, field);

    JSONObject json = new JSONObject();
    json.put("query", query);
    json.put("suggestions", complete);

    if (callback != null && !callback.trim().isEmpty()) {
        print(callback.trim() + "(" + json.toJSONString() + ")");
    } else {
        print(json.toJSONString());
    }

}

From source file:model.Summary.java

public JSONObject toJSON() {
    JSONObject json = new JSONObject();
    json.put("city", city);
    json.put("health", health);
    json.put("stress", stress);
    json.put("expenses", expenses);
    json.put("historicalExpenses", historicalExpenses);
    return json;//from w  ww . ja va2 s . co m
}

From source file:org.kitodo.data.elasticsearch.index.type.ProjectType.java

@SuppressWarnings("unchecked")
@Override/*from www.  j a v a 2s  .c o  m*/
public HttpEntity createDocument(Project project) {

    JSONObject projectObject = new JSONObject();
    projectObject.put("title", project.getTitle());
    String startDate = project.getStartDate() != null ? formatDate(project.getStartDate()) : null;
    projectObject.put("startDate", startDate);
    String endDate = project.getEndDate() != null ? formatDate(project.getEndDate()) : null;
    projectObject.put("endDate", endDate);
    projectObject.put("numberOfPages", project.getNumberOfPages());
    projectObject.put("numberOfVolumes", project.getNumberOfVolumes());
    projectObject.put("fileFormatDmsExport", project.getFileFormatDmsExport());
    projectObject.put("fileFormatInternal", project.getFileFormatInternal());
    String archived = project.getProjectIsArchived() != null ? project.getProjectIsArchived().toString() : null;
    projectObject.put("archived", archived);
    projectObject.put("processes", addObjectRelation(project.getProcesses()));
    projectObject.put("users", addObjectRelation(project.getUsers()));

    JSONArray projectFileGroups = new JSONArray();
    List<ProjectFileGroup> projectProjectFileGroups = project.getProjectFileGroups();
    for (ProjectFileGroup projectFileGroup : projectProjectFileGroups) {
        JSONObject projectFileGroupObject = new JSONObject();
        projectFileGroupObject.put("name", projectFileGroup.getName());
        projectFileGroupObject.put("path", projectFileGroup.getPath());
        projectFileGroupObject.put("mimeType", projectFileGroup.getMimeType());
        projectFileGroupObject.put("suffix", projectFileGroup.getSuffix());
        projectFileGroupObject.put("folder", projectFileGroup.getFolder());
        projectFileGroups.add(projectFileGroupObject);
    }
    projectObject.put("projectFileGroups", projectFileGroups);

    return new NStringEntity(projectObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.KPI.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from   w  w w .  j a  va 2 s.co m*/
public String showKPI() {
    KPI.api_calls += 1; //tracking the current call
    JSONObject obj = new JSONObject();
    obj.put("src", "t-nova expression evaluation service");
    obj.put("msg", "kpi parameters data");

    obj.put("api-calls-total", api_calls);
    obj.put("api-calls-failed", api_calls_failed);
    obj.put("expressions-evaluated", expressions_evaluated);
    obj.put("expressions-under-evaluation", expressions_under_evaluation);
    Date date = new Date(lastknownunixtime);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    String formattedDate = sdf.format(date);
    obj.put("data-since", formattedDate);

    KPI.api_calls_success += 1;
    obj.put("api-calls-success", api_calls_success);
    //lastknownunixtime = System.currentTimeMillis();
    initialize();
    logger.info("URI:/kpi Method:GET Request procesed. The KPI parameters have been reset.");
    return obj.toJSONString();
}

From source file:com.imagelake.android.myuploads.CreateMyUploadthumbnail.java

public String createThumb(int uid) {
    System.out.println("uid=" + uid);
    String img = "";
    List<Images> imlist = idi.getMyUpload(uid);
    if (!imlist.isEmpty()) {

        for (Images images : imlist) {
            if (images.getUser_user_id() == uid) {
                if (images.getImage_state_image_state_id() != 7) {

                    JSONObject jo = new JSONObject();
                    jo.put("img_id", images.getImages_id());
                    jo.put("title", images.getTitle());
                    jo.put("state", images.getImage_state_image_state_id());
                    jo.put("url", images.getImg_url());
                    ja.add(jo);//ww  w.ja v  a 2  s  .  c o m
                }
            }
        }
        if (!ja.isEmpty()) {
            img = "json=" + ja.toJSONString();
        } else {
            img = "msg=No item found.";
        }
    } else {
        img = "msg=No item found.";
    }
    System.gc();
    return img;
}

From source file:montodesktopcalculator.MontoManager.java

public final void sendMessage(String contents) {
    System.out.println("Sending " + contents);
    JSONObject obj = new JSONObject();
    obj.put("source", "java-frontend");
    obj.put("language", "calc");
    obj.put("contents", contents);
    obj.put("selections", "");
    toMonto.send(obj.toJSONString().getBytes());
    toMonto.recv();// ww w. j  a  v  a2s  . c o m
}

From source file:net.duckling.ddl.web.api.APIStarmarkEditController.java

@SuppressWarnings("unchecked")
@RequestMapping//w  ww. j  av  a 2s . co  m
public void service(HttpServletRequest request, HttpServletResponse response) {
    Site site = findSite(request);
    int tid = site.getId();
    int rid = getRid(request, site);
    String uid = findUser(request);
    String operate = request.getParameter("operate");
    if ("add".equals(operate)) {
        starmarkService.addStarmark(uid, rid, tid);
    } else if ("remove".equals(operate)) {
        starmarkService.removeStarmark(uid, rid, tid);
    }

    JSONObject json = new JSONObject();
    json.put("status", "success");
    json.put("rid", rid);
    JsonUtil.writeJSONObject(response, json);
}

From source file:JavaCloud.Cloud.java

public Token tokenCreate(String name, String funciton_filter, String token_valid_to) throws CoreException {
    JSONObject object = new JSONObject();
    object.put("login", login);
    object.put("pw_hash", Utils.calcHash(password, seed));
    object.put("name", name);
    object.put("function_filter", funciton_filter);
    if (token_valid_to != null)
        object.put("token_valid_to", token_valid_to);

    JSONObject jsontoken = (JSONObject) Utils.request(address, "/user/token/create/", object);
    return new Token(address, login, password, seed, jsontoken);
}