/** * * @return this GfJsonObject * @throws GfJsonException - If the key is null or if the current value associated with the key is * not a JSONArray. */ public GfJsonObject append(String key, Object value) throws GfJsonException { try { jsonObject.append(key, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * * @return this GfJsonObject * @throws GfJsonException If the key is null OR if the value is non-finite number */ public GfJsonObject accumulate(String key, Object value) throws GfJsonException { try { if (jsonObject.has(key)) { jsonObject.append(key, value); } else { // first time always add JSONArray for accumulate - for convenience jsonObject.put(key, new JSONArray().put(value)); } } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
private JSONObject addInclude(JSONObject json, String include) throws JSONException { return json.append("includes", include); }
/** * Append a value to the body[key] * @param key the key * @param value the value to be pushed * @return the Mailjet Request itslef */ public MailjetRequest append(String key, Object value) { _body.append(key, value); return this; }
/** * @return JSONObject versino of LGCommand object */ public JSONObject toJson() { JSONObject jo = new JSONObject(); jo.append("cmd",cmd); jo.append("job_id",jobId); jo.append("ttl", ttl); jo.append("priority",priority); JSONArray adapterListJson = new JSONArray(adapterList); jo.append("adapterList",adapterListJson); jo.append("payload",seedPayload.toJsonString()); return jo; }
public static JSONObject append(JSONObject jsonObject, String key, Object value) { Preconditions.checkNotNull(key); try { jsonObject.append(key, value); } catch (JSONException e) { // TODO Determine when this can happen } return jsonObject; } }
private JSONObject createObject() throws JSONException { JSONObject object = new JSONObject(); object.append("mode", "..."); return object; }
JSONObject request = new JSONObject(); request.append("data", array); byte[] outBytes = jsonObject.toString().getBytes("UTF-8"); out.writeLong(outBytes.length);
JSONObject jsonObj = new JSONObject(); JSONObject jo1 = new JSONObject("{"firstname":"Gloomy","lastname":"Sunday"}"); jsonObj.append("employees", jo1);
public void addMetaData(String name, String value) { if(metadata == null) { metadata = new JSONObject(); } try { JSONObject jo = new JSONObject(); jo.put("name", name); jo.put("value", value); metadata.append("MetaData",jo); } catch(JSONException e) { LOG.warning(e.getMessage()); } } public String getMetaDataName(int i) {
protected void appendWidgetInformation(OgemaHttpRequest req, JSONObject result) { JSONObject widgetJson = getWidgetInformation(req); result.append(id, widgetJson); }
@Override public Object resolve(Context c, Map<String, String[]> parameters, Map<String, InputStream> dataStreams) throws JSONException { JSONArray ja = getObjAsJsonArray(c, parameters, dataStreams); if (ja == null) ja = new JSONArray(); JSONObject result = new JSONObject(); for (int i = 0;i < ja.length();i++) { String s = ja.getString(i); result.append(s, s); } return result; }
private JSONObject addInclude(JSONObject json, String include) throws JSONException { return json.append("includes", include); }
JSONObject result = new JSONObject(); JSONArray array1 = new JSONArray(); for (List<Map<String, String>> tmpList : finalOutput) { JSONArray array2 = new JSONArray(); for (int i = 0; i < tmpList.size(); i++) { Map<String, String> insideMap = tmpList.get(i); JSONObject obj = new JSONObject(insideMap); array2.add(obj); } array1.add(array2); } result.append("result", array1); return result.toString();
/** * Sets a job to STOPPED and then deletes it. Endpoint available at /rest/v2/delete/{id} * @param jobId * @return Returns a Response object with body as standard job return format containing result of delete request. */ @DELETE @Path("/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public Response delete(@PathParam("id") String jobId) throws Exception { JSONObject params = Utils.getRequestParameters(request); params.put("ids", new JSONArray().put(jobId)); Utils.addChildIDs(params); params.append("do", "delete"); return Utils.doDelete(params); }
@Override public JSONObject toJson() { if (m_layoutData == null) { return null; } JSONObject json = new JSONObject(); json.put("cacheKey", m_layoutData.getCacheKey()); for (BenchColumnData col : m_layoutData.getColumns()) { json.append("columns", JsonColumnData.toJson(col)); } return json; }
protected void handleModelResourcesDeleted(List<? extends Resource> resources) { if (resources.isEmpty()) { return; } JSONObject jsonEvent = new JSONObject(); for (Resource resource : resources) { String resourceId = getResourceId(resource); jsonEvent.append("resourceIds", resourceId); disposeResource(resource); } addActionEvent(EVENT_RESOURCES_DELETED, jsonEvent); }
@Override public JSONObject toJson() { JSONObject json = new JSONObject(); json.put("message", m_status.getMessage()); json.put("severity", m_status.getSeverity()); json.put("iconId", m_status.getIconId()); json.put("code", m_status.getCode()); if (m_status.isMultiStatus()) { for (IStatus cs : ((IMultiStatus) m_status).getChildren()) { json.append("children", new JsonStatus(cs).toJson()); } } return json; }
@Override public JSONObject toJson() { if (getLayoutData() == null) { return null; } JSONObject json = super.toJson(); for (FlexboxLayoutData rowData : getLayoutData().getRows()) { json.append("rows", JsonLayoutData.toJson(rowData)); } return json; }
@Test public void testObjectFormatting() { JSONObject obj = new JSONObject(); checkJsonOkResponse("{}", jsonOkResponse(obj)); obj.put("hello", "hi"); checkJsonOkResponse("{\"hello\": \"hi\"}", jsonOkResponse(obj)); obj.append("hey", "hello"); checkJsonOkResponse("{\n \"hello\": \"hi\",\n \"hey\": [\"hello\"]\n}", jsonOkResponse(obj)); obj.append("hey", "hey"); checkJsonOkResponse("{\n \"hello\": \"hi\",\n \"hey\": [\n \"hello\",\n \"hey\"\n ]\n}", jsonOkResponse(obj)); }