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:jsonconverter.createandwrite.JSONObjectCreator.java

public JSONObject objectArranger() {

    JSONArray array = new JSONArray();
    for (JSONSearchObjectCreator searchObject : arraySearchObjs) {
        JSONObject tempObj = new JSONObject();

        tempObj.put("id", searchObject.getId());
        tempObj.put("path", searchObject.getPath());
        tempObj.put("title", searchObject.getTitle());
        tempObj.put("frag", searchObject.getFragment());

        array.add(tempObj);/*from w  w  w .j a v  a 2s . co  m*/
    }

    obj.put("Search", array);

    return obj;
}

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

@Override
public String serve(HttpServletRequest request) {

    logger.debug("start serving request");
    if (keywordMatcher.match(request)) {
        return doProcess(request);
    } else {/*from   w w  w.java  2  s. com*/

        if (nextServiceHandler != null) {
            return nextServiceHandler.serve(request);
        } else {
            logger.debug("cannot find any Handler to serve");
            JSONObject json = new JSONObject();
            json.put("error", "no handler found");

            return json.toJSONString();
        }

    }
}

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

public void testBirthday() {
    JSONObject json = new JSONObject();
    json.put("birthday", "2001-01-01");
    Validators v = new Validators(json);
    v.add("birthday", v.birthday());
    assertTrue(v.validate());//from   w w  w.ja  v  a  2 s.c  o  m
}

From source file:net.duckling.ddl.web.AbstractRecommendContrller.java

@SuppressWarnings("unchecked")
protected void prepareRecommend(HttpServletResponse response) {
    Team team = teamService.getTeamByID(VWBContext.getCurrentTid());
    List<SimpleUser> candidates = teamMemberService.getTeamMembersOrderByName(team.getId());
    Collections.sort(candidates, comparator);
    JSONArray array = new JSONArray();
    for (SimpleUser current : candidates) {
        JSONObject temp = new JSONObject();
        temp.put("id", current.getUid());
        if (StringUtils.isNotEmpty(current.getName())) {
            temp.put("name", current.getName());
        } else {/*www . j av  a 2  s  .  c  om*/
            temp.put("name", current.getUid());
        }
        temp.put("userExtId", current.getId());
        array.add(temp);
    }
    JsonUtil.writeJSONObject(response, array);
}

From source file:modelo.AutenticacionManager.PermisosAcceso.java

public JSONObject insertarPermisos(int codigo_rol, int codigo_pantalla, String valor) throws Exception {

    InsertarPermisos insert = new InsertarPermisos(codigo_rol, codigo_pantalla, valor);

    insert.ejecutar();// w w w.j a v a2  s .  co m

    Integer respuesta = insert.getResultado();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("resp", respuesta);

    return jsonObject;

}

From source file:com.endgame.binarypig.util.JsonUtilTest.java

public void testIt() {
    JsonUtil ju = new JsonUtil();

    JSONArray list = new JSONArray();
    list.add("1");
    list.add("2");
    list.add("3");

    JSONObject value = new JSONObject();
    value.put("name", "Jason");
    value.put("null", null);
    value.put("num", 7);
    value.put("bool", true);
    value.put("list", list);

    Object wrapped = ju.wrap(value);
    assertTrue(wrapped instanceof Map);

    Map map = (Map) wrapped;
    assertEquals(map.get("name"), "Jason");
    assertNull(map.get("null"));
    assertEquals(map.get("num"), "7");
    assertEquals(map.get("bool"), "true");
    List<Tuple> tuples = Arrays.asList(TupleFactory.getInstance().newTuple((Object) "1"),
            TupleFactory.getInstance().newTuple((Object) "2"),
            TupleFactory.getInstance().newTuple((Object) "3"));

    assertEquals(map.get("list"), new NonSpillableDataBag(tuples));

}

From source file:com.mobicage.rogerthat.form.AbstractTextWidget.java

@Override
@SuppressWarnings("unchecked")
public JSONObject toJSONObject() {
    JSONObject result = new JSONObject();
    result.put("value", value);
    result.put("place_holder", placeHolder);
    result.put("max_chars", maxChars);
    return result;
}

From source file:com.mobicage.rogerthat.form.RangeSlider.java

@Override
@SuppressWarnings("unchecked")
public JSONObject toJSONObject() {
    JSONObject result = super.toJSONObject();
    result.put("low_value", lowValue);
    result.put("high_value", highValue);
    return result;
}

From source file:com.oic.event.GetUserInfo.java

@Override
public void ActionEvent(JSONObject json, WebSocketListener webSocket) {
    JSONObject responseJSON = new JSONObject();
    responseJSON.put("method", "getuserinfo");
    OicCharacter c = webSocket.getCharacter();
    long userid = c.getUserId();
    int mapid = c.getMapid();
    if (validation(json)) {
        userid = Long.parseLong(json.get("userid").toString());
        mapid = Integer.parseInt(json.get("mapid").toString());
    }/*w w w  . j  a  va  2s  .c  o  m*/
    System.out.println("mapid : " + mapid);
    System.out.println("userid : " + userid);
    try {
        getUserinfo(responseJSON, userid, mapid);
    } catch (NullPointerException e) {
        responseJSON.put("status", 1);
    }
    webSocket.sendJson(responseJSON);
}

From source file:com.rackspacecloud.blueflood.outputs.serializers.BatchedMetricsJSONOutputSerializer.java

@Override
public JSONObject transformRollupData(Map<Locator, MetricData> metricData, Set<MetricStat> filterStats)
        throws SerializationException {
    final JSONObject globalJSON = new JSONObject();
    final JSONArray metricsArray = new JSONArray();

    for (Map.Entry<Locator, MetricData> one : metricData.entrySet()) {
        final JSONObject singleMetricJSON = new JSONObject();
        singleMetricJSON.put("metric", one.getKey().getMetricName());
        singleMetricJSON.put("unit",
                one.getValue().getUnit() == null ? Util.UNKNOWN : one.getValue().getUnit());
        singleMetricJSON.put("type", one.getValue().getType());
        Set<MetricStat> oneFilterStats = fixFilterStats(one.getValue(), filterStats);
        JSONArray values = transformDataToJSONArray(one.getValue(), oneFilterStats);
        singleMetricJSON.put("data", values);
        metricsArray.add(singleMetricJSON);
    }// ww w.j  a v a 2 s . c  om

    globalJSON.put("metrics", metricsArray);
    return globalJSON;
}