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.entities.EntityInventory.java

@SuppressWarnings("unchecked")
@Override//from w w  w  .  ja v a 2s.  c  om
public void saveTo(JSONObject jsonObject) {
    jsonObject.put("items", items);
}

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

@RequestMapping
public void init(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String uid = findUser(req);//from   w  w  w.  java2  s .  co m
    if (StringUtils.isEmpty(uid) || "Guest".equals(uid)) {
        resp.sendError(401);
        JSONObject obj = new JSONObject();
        obj.put("error", "!");
        JsonUtil.writeJSONObject(resp, obj);
        return;
    }
    String sessionId = req.getSession().getId();
    AndroidMessageBean bean = androidNoticeHandler.getUserMessage(uid, sessionId);
    JSONObject obj = new JSONObject();
    addMessage(bean, obj);
    if (bean.getLatestMessageTeamId() > 0) {
        Team team = teamService.getTeamByID(bean.getLatestMessageTeamId());
        if (team != null) {
            obj.put("latestMesageTeamCode", team.getName());
            obj.put("latestMesageTeamName", team.getDisplayName());
        }
    }
    JsonUtil.writeJSONObject(resp, obj);
}

From source file:com.conwet.silbops.msg.Message.java

@Override
@SuppressWarnings("unchecked")
public final JSONObject toJSON() {

    JSONObject json = new JSONObject();
    json.put("type", type.toJSON());
    json.put("payload", getPayloadAsJSON());

    return json;/*from www . ja  v a  2 s.  c om*/
}

From source file:com.conwet.xjsp.features.MessageChannel.java

@SuppressWarnings("unchecked")
synchronized public void sendErrorMessage(Object payload) throws IOException {
    JSONObject message = new JSONObject();
    message.put("id", nextId());
    message.put("type", XJSPConstants.XJSP_PREFIX + ":error");
    message.put("message", payload);
    sendFragment(message.toJSONString());
}

From source file:com.facebook.tsdb.tsdash.server.TsdbServlet.java

@SuppressWarnings("unchecked")
protected String getErrorResponse(Throwable e) {
    JSONObject errObj = new JSONObject();
    errObj.put("error", e.getMessage());
    StringWriter stackTrace = new StringWriter();
    e.printStackTrace(new PrintWriter(stackTrace));
    errObj.put("stacktrace", stackTrace.toString());
    return errObj.toJSONString();
}

From source file:hobbyshare.testclient.RestService_TestClient.java

public void test_Login() {
    HttpClient httpClient = HttpClientBuilder.create().build();

    JSONObject loginAttempt = new JSONObject();
    loginAttempt.put("password", "1234");
    loginAttempt.put("userName", "77_username");

    try {//from  w w  w  .j a  va2s  . com
        HttpPost request = new HttpPost("http://localhost:8095/login");
        StringEntity params = new StringEntity(loginAttempt.toString());
        request.addHeader("content-type", "application/json");
        request.setEntity(params);
        HttpResponse response = httpClient.execute(request);

        System.out.println("---Testing Login----");
        System.out.println(response.toString());
        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseString);
        System.out.println("----End of login Test----");
    } catch (Exception ex) {
        // handle exception here
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:JavaCloud.Models.Image.java

public void upload_data(String data, long offset) throws CoreException {
    JSONObject object = new JSONObject();
    object.put("token", token);
    object.put("image_id", id);
    object.put("offset", offset);
    object.put("data", data);
    Utils.request(address, "/api/image/upload_data/", object);
}

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

@SuppressWarnings("unchecked")
@Override//from  ww w .  j  a v a  2  s  .  co  m
public HttpEntity createDocument(Process process) {

    LinkedHashMap<String, String> orderedProcessMap = new LinkedHashMap<>();
    orderedProcessMap.put("name", process.getTitle());
    orderedProcessMap.put("outputName", process.getOutputName());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String creationDate = process.getCreationDate() != null ? dateFormat.format(process.getCreationDate())
            : null;
    orderedProcessMap.put("creationDate", creationDate);
    orderedProcessMap.put("wikiField", process.getWikiField());
    String project = process.getProject() != null ? process.getProject().getId().toString() : "null";
    orderedProcessMap.put("project", project);
    String ruleset = process.getRuleset() != null ? process.getRuleset().getId().toString() : "null";
    orderedProcessMap.put("ruleset", ruleset);
    String ldapGroup = process.getDocket() != null ? process.getDocket().getId().toString() : "null";
    orderedProcessMap.put("ldapGroup", ldapGroup);

    JSONObject processObject = new JSONObject(orderedProcessMap);

    JSONArray properties = new JSONArray();
    List<ProcessProperty> processProperties = process.getProperties();
    for (ProcessProperty property : processProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    processObject.put("properties", properties);

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

From source file:com.conwet.xjsp.features.MessageChannel.java

@SuppressWarnings("unchecked")
synchronized public void sendErrorMessage(int errorCode, String errorMessage, String sourceId)
        throws IOException {
    JSONObject payload = new JSONObject();
    payload.put("code", errorCode);
    payload.put("message", errorMessage);
    payload.put("id", sourceId);
    sendErrorMessage(payload);/*from w w  w.j  a  v  a 2 s  . co  m*/
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.TemperatureQuery.java

@SuppressWarnings("unchecked")
public String execute(IServletConfig config, String[] parameters) {

    JSONArray obj = new JSONArray();

    for (IVirtualVehicle vehicle : vehicleMap.values()) {
        if (vehicle.isFrozen()) {
            continue;
        }//from ww w  . jav a 2  s. c  o m

        List<ITask> cmdList = vehicle.getTaskList();

        for (ITask cmd : cmdList) {
            for (IAction action : cmd.getActionList()) {
                if (action instanceof Temperature && action.isComplete()) {
                    Temperature actionTemp = (Temperature) action;
                    JSONObject o = new JSONObject();
                    o.put("lat", Double.valueOf(cmd.getPosition().getLatitude()));
                    o.put("lon", Double.valueOf(cmd.getPosition().getLongitude()));
                    //                  o.put("alt", Double.valueOf(cmd.getPosition().getAltitude()));
                    o.put("temp", Double.valueOf(actionTemp.getTemperature()));
                    obj.add(o);
                }
            }
        }
    }

    return JSONValue.toJSONString(obj);
}