List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:org.nuxeo.connect.data.PackageDescriptor.java
@JSONExportMethod(name = "provides") protected JSONArray getProvidesAsJSON() { JSONArray deps = new JSONArray(); for (PackageDependency dep : getProvides()) { deps.put(dep.toString()); }/*from w w w. j a va2 s . c o m*/ return deps; }
From source file:net.micode.notes.gtask.remote.GTaskClient.java
public void createTask(Task task) throws NetworkFailureException { commitUpdate();// ww w . ja v a2 s . c o m try { JSONObject jsPost = new JSONObject(); JSONArray actionList = new JSONArray(); // action_list actionList.put(task.getCreateAction(getActionId())); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // client_version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // post JSONObject jsResponse = postRequest(jsPost); JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_RESULTS).get(0); task.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("create task: handing jsonobject failed"); } }
From source file:net.micode.notes.gtask.remote.GTaskClient.java
public void createTaskList(TaskList tasklist) throws NetworkFailureException { commitUpdate();/*from w ww . ja va 2 s .c o m*/ try { JSONObject jsPost = new JSONObject(); JSONArray actionList = new JSONArray(); // action_list actionList.put(tasklist.getCreateAction(getActionId())); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // client version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // post JSONObject jsResponse = postRequest(jsPost); JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_RESULTS).get(0); tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("create tasklist: handing jsonobject failed"); } }
From source file:net.micode.notes.gtask.remote.GTaskClient.java
public void moveTask(Task task, TaskList preParent, TaskList curParent) throws NetworkFailureException { commitUpdate();/*from w w w .j a v a 2s. c o m*/ try { JSONObject jsPost = new JSONObject(); JSONArray actionList = new JSONArray(); JSONObject action = new JSONObject(); // action_list action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE); action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid()); if (preParent == curParent && task.getPriorSibling() != null) { // put prioring_sibing_id only if moving within the tasklist and // it is not the first one action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling()); } action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid()); action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid()); if (preParent != curParent) { // put the dest_list only if moving between tasklists action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid()); } actionList.put(action); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // client_version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); postRequest(jsPost); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("move task: handing jsonobject failed"); } }
From source file:net.micode.notes.gtask.remote.GTaskClient.java
public void deleteNode(Node node) throws NetworkFailureException { commitUpdate();/*from w ww . ja v a2 s . c o m*/ try { JSONObject jsPost = new JSONObject(); JSONArray actionList = new JSONArray(); // action_list node.setDeleted(true); actionList.put(node.getUpdateAction(getActionId())); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // client_version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); postRequest(jsPost); mUpdateArray = null; } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("delete node: handing jsonobject failed"); } }
From source file:net.micode.notes.gtask.remote.GTaskClient.java
public JSONArray getTaskList(String listGid) throws NetworkFailureException { commitUpdate();/* w ww .j a v a 2s .com*/ try { JSONObject jsPost = new JSONObject(); JSONArray actionList = new JSONArray(); JSONObject action = new JSONObject(); // action_list action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL); action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); action.put(GTaskStringUtils.GTASK_JSON_LIST_ID, listGid); action.put(GTaskStringUtils.GTASK_JSON_GET_DELETED, false); actionList.put(action); jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // client_version jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); JSONObject jsResponse = postRequest(jsPost); return jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_TASKS); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("get task list: handing jsonobject failed"); } }
From source file:com.bluepandora.therap.donatelife.jsonbuilder.DistrictJson.java
public static JSONObject getDistrictJson(ResultSet result) throws JSONException { JSONObject jsonObject;// www .ja va2 s. c o m JSONArray jsonArray = new JSONArray(); try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(DIST_ID, result.getString("dist_id")); jsonObject.put(DIST_NAME, result.getString("dist_name")); jsonObject.put(DIST_BNAME, result.getString("dist_bname")); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(DISTRICT, jsonArray); jsonObject.put(DONE, 1); } catch (SQLException error) { Debug.debugLog("DISTRICT JSON ERROR: ", error); jsonObject = new JSONObject(); jsonObject.put(DONE, 0); } return jsonObject; }
From source file:com.openerp.addons.note.EditNoteFragment.java
public void updateNote(int row_id) { try {//from ww w . j a va2s . c o m JSONArray tagID = db.getSelectedTagId(selectedTags); long stage_id = Long.parseLong(stages.get(noteStages.getSelectedItem().toString())); ContentValues values = new ContentValues(); JSONObject vals = new JSONObject(); // If Pad Installed Over Server if (padAdded) { JSONArray url = new JSONArray(); url.put(originalMemo); JSONObject obj = oe_obj.call_kw("pad.common", "pad_get_content", url); // HTMLHelper helper = new HTMLHelper(); String link = HTMLHelper.htmlToString(obj.getString("result")); values.put("stage_id", stage_id); vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString())); values.put("name", db.generateName(link)); vals.put("name", values.get("name").toString()); values.put("memo", obj.getString("result")); vals.put("memo", values.get("memo").toString()); values.put("note_pad_url", originalMemo); vals.put("note_pad_url", values.get("note_pad_url").toString()); } // If Pad Not Installed Over Server else { values.put("stage_id", stage_id); vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString())); values.put("name", db.generateName(noteMemo.getText().toString())); vals.put("name", values.get("name").toString()); values.put("memo", Html.toHtml(noteMemo.getText())); vals.put("memo", values.get("memo").toString()); } JSONArray tag_ids = new JSONArray(); tag_ids.put(6); tag_ids.put(false); JSONArray c_ids = new JSONArray(tagID.toString()); tag_ids.put(c_ids); vals.put("tag_ids", new JSONArray("[" + tag_ids.toString() + "]")); // This will update Notes over Server And Local database db = new NoteDBHelper(scope.context()); if (oe_obj.updateValues(db.getModelName(), vals, row_id)) { db.write(db, values, row_id, true); db.executeSQL("delete from note_note_note_tag_rel where note_note_id = ? and oea_name = ?", new String[] { row_id + "", scope.User().getAndroidName() }); for (int i = 0; i < tagID.length(); i++) { ContentValues rel_vals = new ContentValues(); rel_vals.put("note_note_id", row_id); rel_vals.put("note_tag_id", tagID.getInt(i)); rel_vals.put("oea_name", scope.User().getAndroidName()); SQLiteDatabase insertDb = db.getWritableDatabase(); insertDb.insert("note_note_note_tag_rel", null, rel_vals); insertDb.close(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.icclab.cyclops.dashboard.users.Admin.java
@Put public Representation updateAdmins(Representation entity) { String sessionId = ""; JSONArray admins;//from w w w.j a v a2 s .co m JSONObject updateObject = new JSONObject(); try { JsonRepresentation represent = new JsonRepresentation(entity); JSONObject requestJson = represent.getJsonObject(); JSONArray uniqueMembers = new JSONArray(); admins = requestJson.getJSONArray("admins"); sessionId = requestJson.getString("sessionId"); String adminGroupName = LoadConfiguration.configuration.get("OPENAM_ADMIN_GROUP_NAME"); String adminEntryPattern = LoadConfiguration.configuration.get("OPENAM_ADMIN_USER_PATTERN"); updateObject.put("name", adminGroupName); updateObject.put("realm", "/"); updateObject.put("cn", new JSONArray(new String[] { adminGroupName })); updateObject.put("description", ""); for (int i = 0; i < admins.length(); i++) { String adminName = admins.getString(i); String uniqueMember = adminEntryPattern.replace("{{USERNAME}}", adminName); uniqueMembers.put(uniqueMember); } updateObject.put("uniquemember", uniqueMembers); } catch (JSONException e) { //TODO: error handling } catch (IOException e) { //TODO: error handling } String url = LoadConfiguration.configuration.get("OPENAM_LIST_ADMINS_URL"); ClientResource clientResource = new ClientResource(url); Series<Header> headers = (Series<Header>) clientResource.getRequestAttributes() .get("org.restlet.http.headers"); if (headers == null) { headers = new Series<Header>(Header.class); clientResource.getRequestAttributes().put("org.restlet.http.headers", headers); } headers.set("iPlanetDirectoryPro", sessionId); return clientResource.put(updateObject); }
From source file:ded.model.Diagram.java
@Override public JSONObject toJSON() { JSONObject o = new JSONObject(); try {/*from ww w. j ava2 s. c o m*/ o.put("type", jsonType); o.put("version", currentFileVersion); o.put("windowSize", AWTJSONUtil.dimensionToJSON(this.windowSize)); o.put("drawFileName", this.drawFileName); // Map from an entity to its position in the serialized // 'entities' array, so it can be referenced by inheritances // and relations. HashMap<Entity, Integer> entityToInteger = new HashMap<Entity, Integer>(); // Entities. JSONArray arr = new JSONArray(); int index = 0; for (Entity e : this.entities) { entityToInteger.put(e, index++); arr.put(e.toJSON()); } o.put("entities", arr); // Map from inheritance to serialized position. HashMap<Inheritance, Integer> inheritanceToInteger = new HashMap<Inheritance, Integer>(); // Inheritances. arr = new JSONArray(); index = 0; for (Inheritance inh : this.inheritances) { inheritanceToInteger.put(inh, index++); arr.put(inh.toJSON(entityToInteger)); } o.put("inheritances", arr); // Relations. arr = new JSONArray(); index = 0; for (Relation rel : this.relations) { arr.put(rel.toJSON(entityToInteger, inheritanceToInteger)); } o.put("relations", arr); } catch (JSONException e) { assert (false); } return o; }