List of usage examples for org.json JSONWriter value
public JSONWriter value(Object object) throws JSONException
From source file:org.everit.osgi.webconsole.configuration.DisplayedAttribute.java
private void valueToJSON(final JSONWriter writer) { writer.array();//from www . j a v a 2s. com for (String value : Optional.ofNullable(this.value).orElse(new String[0])) { if (type.equals("boolean")) { writer.value(value.equals("true")); } else { writer.value(value); } } writer.endArray(); }
From source file:org.everit.osgi.webconsole.configuration.ServiceSuggestion.java
public void toJSON(final JSONWriter writer) { writer.object();//from w ww .j a v a 2 s .c o m writer.key("serviceClass"); writer.value(serviceClass); writer.key("id"); writer.value(serviceId); writer.key("properties"); writer.array(); for (String key : serviceProperties.keySet()) { writer.object(); writer.key("key"); writer.value(key); writer.key("value"); writer.value(serviceProperties.get(key)); writer.endObject(); } writer.endArray(); writer.endObject(); }
From source file:org.apache.felix.webconsole.internal.deppack.DepPackServlet.java
private void jsonKeyVal(JSONWriter jsonWriter, String key, Object value) throws JSONException { if (key != null && value != null) { jsonWriter.object();/* w ww .j a va 2 s . c o m*/ jsonWriter.key("key"); jsonWriter.value(key); jsonWriter.key("value"); jsonWriter.value(value); jsonWriter.endObject(); } }
From source file:util.CacheUtil.java
private static String genJsonConfigV250(Extra extra, List<Ration> rations) throws JSONException { JSONWriter jsonWriter = new JSONStringer(); if (extra.getAdsOn() == 0) { return jsonWriter.object().key("rations").array().endArray().endObject().toString(); }//from w w w. j av a 2s. c o m jsonWriter = jsonWriter.object().key("extra").object().key("location_on").value(extra.getLocationOn()) .key("background_color_rgb").object().key("red").value(extra.getBg_red()).key("green") .value(extra.getBg_green()).key("blue").value(extra.getBg_blue()).key("alpha") .value(extra.getBg_alpha()).endObject().key("text_color_rgb").object().key("red") .value(extra.getFg_red()).key("green").value(extra.getFg_green()).key("blue") .value(extra.getFg_blue()).key("alpha").value(extra.getFg_alpha()).endObject().key("cycle_time") .value(extra.getCycleTime()).key("transition").value(extra.getTransition()).endObject(); jsonWriter = jsonWriter.key("rations").array(); for (Ration ration : rations) { jsonWriter = jsonWriter.object().key("nid").value(ration.getNid()).key("type").value(ration.getType()) .key("nname").value(ration.getNName()).key("weight").value(ration.getWeight()).key("priority") .value(ration.getPriority()).key("key"); if (ration.getType() == AdWhirlUtil.NETWORKS.VIDEOEGG.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); jsonWriter = jsonWriter.object().key("publisher").value(temp[0]).key("area").value(temp[1]) .endObject(); } else if (ration.getType() == AdWhirlUtil.NETWORKS.JUMPTAP.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); if (temp.length == 3) { jsonWriter = jsonWriter.object().key("publisherID").value(temp[0]).key("siteID").value(temp[1]) .key("spotID").value(temp[2]).endObject(); } else if (temp.length == 2) { jsonWriter = jsonWriter.object().key("publisherID").value(temp[0]).key("siteID").value(temp[1]) .endObject(); } else { jsonWriter = jsonWriter.object().key("publisherID").value(temp[0]).endObject(); } } else if (ration.getType() == AdWhirlUtil.NETWORKS.QUATTRO.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); jsonWriter = jsonWriter.object().key("siteID").value(temp[0]).key("publisherID").value(temp[1]) .endObject(); } else if (ration.getType() == AdWhirlUtil.NETWORKS.MOBCLIX.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); if (temp.length == 2) { jsonWriter = jsonWriter.object().key("appID").value(temp[0]).key("adCode").value(temp[1]) .endObject(); } else { jsonWriter = jsonWriter.object().key("appID").value(temp[0]).endObject(); } } else { jsonWriter = jsonWriter.value(ration.getNetworkKey()); } jsonWriter = jsonWriter.endObject(); } jsonWriter = jsonWriter.endArray(); return jsonWriter.endObject().toString(); }
From source file:util.CacheUtil.java
private static String genJsonConfigV200(Extra extra, List<Ration> rations) throws JSONException { JSONWriter jsonWriter = new JSONStringer(); if (extra.getAdsOn() == 0) { return jsonWriter.object().key("rations").array().endArray().endObject().toString(); }/*w w w.ja v a 2 s . co m*/ jsonWriter = jsonWriter.object().key("extra").object().key("location_on").value(extra.getLocationOn()) .key("background_color_rgb").object().key("red").value(extra.getBg_red()).key("green") .value(extra.getBg_green()).key("blue").value(extra.getBg_blue()).key("alpha") .value(extra.getBg_alpha()).endObject().key("text_color_rgb").object().key("red") .value(extra.getFg_red()).key("green").value(extra.getFg_green()).key("blue") .value(extra.getFg_blue()).key("alpha").value(extra.getFg_alpha()).endObject().key("cycle_time") .value(extra.getCycleTime()).key("transition").value(extra.getTransition()).endObject(); jsonWriter = jsonWriter.key("rations").array(); for (Ration ration : rations) { jsonWriter = jsonWriter.object().key("nid").value(ration.getNid()).key("type").value(ration.getType()) .key("nname").value(ration.getNName()).key("weight").value(ration.getWeight()).key("priority") .value(ration.getPriority()).key("key"); if (ration.getType() == AdWhirlUtil.NETWORKS.VIDEOEGG.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); jsonWriter = jsonWriter.object().key("publisher").value(temp[0]).key("area").value(temp[1]) .endObject(); } else if (ration.getType() == AdWhirlUtil.NETWORKS.JUMPTAP.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); jsonWriter = jsonWriter.value(temp[0]); } else if (ration.getType() == AdWhirlUtil.NETWORKS.QUATTRO.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); jsonWriter = jsonWriter.object().key("siteID").value(temp[0]).key("publisherID").value(temp[1]) .endObject(); } else if (ration.getType() == AdWhirlUtil.NETWORKS.MOBCLIX.ordinal()) { String[] temp = ration.getNetworkKey().split(AdWhirlUtil.KEY_SPLIT); if (temp.length == 2) { jsonWriter = jsonWriter.object().key("appID").value(temp[0]).key("adCode").value(temp[1]) .endObject(); } else { jsonWriter = jsonWriter.object().key("appID").value(temp[0]).endObject(); } } else { jsonWriter = jsonWriter.value(ration.getNetworkKey()); } jsonWriter = jsonWriter.endObject(); } jsonWriter = jsonWriter.endArray(); return jsonWriter.endObject().toString(); }