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:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Course.java

@SuppressWarnings("unchecked")
@Override//w w w.  j a  v  a2s .  co  m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "course");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", courseOverGround);
    }
    return o.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//from  w  w w. j  a  va  2  s .  co  m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_RANDOM);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", random);
    }
    return o.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//from  w w w. j  a  va  2s  .  c  o m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_SONAR);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", sonar);
    }
    return o.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//from www. j a va2s .c  o m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "speed");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", speedOverGround);
    }
    return o.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//from   www  . j  av  a  2 s  .  c om
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_TEMPERATURE);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", temperature);
    }
    return o.toJSONString();
}

From source file:JavaCloud.Models.Token.java

public void delete() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("login", login);
    object.put("pw_hash", Utils.calcHash(password, seed));
    object.put("token_id", id);
    Utils.request(address, "/user/token/delete/", object);
}

From source file:com.mobicage.rogerthat.SendApiCallCallbackResult.java

@SuppressWarnings("unchecked")
@Override/*from   w w w.  j  av a2s . c om*/
public JSONObject toJSONObject() {
    JSONObject result = new JSONObject();
    result.put("error", this.error);
    result.put("result", this.result);
    return result;
}

From source file:di.uniba.it.tee2.api.v1.NaturalSearchService.java

@GET
public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery,
        @QueryParam("n") int n) {
    try {/*from   w w w.  ja  va 2  s  .c om*/
        SearchServiceWrapper instance = SearchServiceWrapper.getInstance(
                ServerConfig.getInstance().getProperty("search.language"),
                ServerConfig.getInstance().getProperty("search.index"));
        List<SearchResult> search = instance.getSearch().naturalSearch(query, timeQuery, n);
        JSONObject json = new JSONObject();
        json.put("size", search.size());
        JSONArray results = new JSONArray();
        for (SearchResult sr : search) {
            results.add(sr.toJSON());
        }
        json.put("results", results);
        return Response.ok(json.toString()).build();
    } catch (Exception ex) {
        Logger.getLogger(NaturalSearchService.class.getName()).log(Level.SEVERE, null, ex);
        return Response.serverError().build();
    }
}

From source file:di.uniba.it.tee2.api.v1.SearchService.java

@GET
public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery,
        @QueryParam("n") int n) {
    try {/*  w w w.jav a 2 s . co  m*/
        SearchServiceWrapper instance = SearchServiceWrapper.getInstance(
                ServerConfig.getInstance().getProperty("search.language"),
                ServerConfig.getInstance().getProperty("search.index"));
        List<SearchResult> search = instance.getSearch().search(query, timeQuery, n);
        JSONObject json = new JSONObject();
        json.put("size", search.size());
        JSONArray results = new JSONArray();
        for (SearchResult sr : search) {
            results.add(sr.toJSON());
        }
        json.put("results", results);
        return Response.ok(json.toString()).build();
    } catch (Exception ex) {
        Logger.getLogger(SearchService.class.getName()).log(Level.SEVERE, null, ex);
        return Response.serverError().build();
    }
}

From source file:Json.Type.java

public Type(String type) {
    JSONObject obj = new JSONObject();
    obj.put("type", type);
    File file = new File("type");

    try {//  w  w  w.  j ava  2 s  .  c  om
        //?,  ?   ??  ? 
        if (!file.exists()) {
            file.createNewFile();
        }

        //PrintWriter ? ? ?  
        PrintWriter out = new PrintWriter(file.getAbsoluteFile());

        try {
            //? ?  
            out.print(obj);
        } finally {
            //?     
            //   ??
            out.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}