@SuppressWarnings("unchecked") public void removeProperty(Object obj, Object key) { if (isMap(obj)) toJsonObject(obj).remove(key.toString()); else { JSONArray array = toJsonArray(obj); int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); array.remove(index); } }
messages.remove(i); nodePushReport.incrementKnownCount(existed); continue;
@SuppressWarnings("unchecked") public void removeProperty(Object obj, Object key) { if (isMap(obj)) toJsonObject(obj).remove(key.toString()); else { JSONArray array = toJsonArray(obj); int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); array.remove(index); } }
public Action removeNextAction() { JSONArray a = getActionsJSON(); if (a.length() == 0) return null; return new Action((JSONObject) this.getJSONArray(KEY_ACTIONS).remove(0)); }
public ESMFactory removeESM(int position) { queue.remove(position); return this; }
public AsonArray<T> remove(int index) { if (index < 0 || index > array.length() - 1) { throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for this array!"); } array.remove(index); return this; }
JSONArray jArray = new JSONArray(); jArray.remove(position); // For remove JSONArrayElement
public static void main(String[] args) throws Exception { String s = "{ \"fields\" : [ "+ " {\"name\":\"First Name\",\"id\":1},"+ "{\"name\":\"Middle Name\",\"id\":2},"+ "{\"name\":\"Last Name\",\"id\":3}"+ "]}"; JSONObject json = new JSONObject(s); System.out.println("original object:"+json); JSONArray fieldsObject =json.getJSONArray("fields"); System.out.println("Before removal :"+fieldsObject); Object remove = fieldsObject.remove(1); System.out.println("After removal :"+fieldsObject); }
private void removeStringFromArray(JSONArray ary, String value) throws Exception { if( null != ary ){ // find index int index = -1; for(int i=0,e=ary.length(); i<e; ++i){ String v = ary.getString(i); if( value.equals(v) ){ index = i; break; } } if( index >= 0 ){ ary.remove(index); } } }
JSONObject root = new JSONObject(json); JSONArray myData = (JSONArray) root.get("myData"); myData.remove(0); myData.put(4); System.out.println("root = " + root.toString());
//instantiate your json array (e.g. from a string, or a file) //String s = "[...]"; String s = FileUtils.readFileToString(new File(yourFile)); JSONArray json = new JSONArray(s); //get the reportKey value: json.get(1).get("reportKey"); //removing it: //removing all the node: {"reportKey":"something"} json.remove(1); //removing only "reportKey":"something" and keeping {}: json.get(1).remove("reportKey");
JSONArray list = new JSONArray(); JSONArray jsonArray = new JSONArray(jsonstring); int len = jsonArray.length(); if (jsonArray != null) { for (int i=0;i<len;i++) { //Excluding the item at position if (i != position) { list.put(jsonArray.get(i)); } } //Remove the element from arraylist list.remove(position); }
public class App{ public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new FileReader("json.txt")); String jsonContent = ""; String jsonLine; while((jsonLine=br.readLine())!=null){ jsonContent+=jsonLine; } JSONObject jObj = new JSONObject(jsonContent); JSONArray jsonArray = jObj.getJSONArray("fields"); jsonArray.remove(1); System.out.println(jsonArray); } }
public static void removeFromJSONArray(JSONArray jsonArray, Object value) { int idx = arrayIndexOf(jsonArray, value); if (idx >= 0) { jsonArray.remove(idx); } }
JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject2 = new JSONObject(); jsonObject.put("key1", "value1"); jsonObject1.put("key2", "value2"); jsonObject2.put("key3", "value3"); jsonArray.add(jsonObject); jsonArray.add(jsonObject1); jsonArray.add(jsonObject2); //........ Whole Json Array System.out.println(jsonArray); //To remove 2nd jsonObject (index starts from 0) jsonArray.remove(1); // Now the array will not have 2nd Object System.out.println(jsonArray);
void setProjectMacros(JSONArray newMacros) throws JSONException { Map<Long, JSONObject> macroMap = new HashMap<>(); for(int i = 0; i < macros.length(); i++) { JSONObject macro = macros.getJSONObject(i); macroMap.put(macro.getLong("serial_number"), macro); } for(int i = 0; i < newMacros.length(); i++) { JSONObject macro = newMacros.getJSONObject(i); macroMap.put(macro.getLong("serial_number"), macro); } while(macros.length() > 0) { macros.remove(0); } for(JSONObject macro : macroMap.values()) { macros.put(macro); } String json = root.toString(4); BurpExtender.callbacks.loadConfigFromJson(json); }
public void removeBookmark(String title) { String result = sp.getString("bookmarks", "[]"); try { JSONArray bookmarksArray = new JSONArray(result); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { bookmarksArray.remove(bookmarkTitles.indexOf(title)); } else { final List<JSONObject> objs = asList(bookmarksArray); objs.remove(bookmarkTitles.indexOf(title)); final JSONArray out = new JSONArray(); for (final JSONObject obj : objs) { out.put(obj); } bookmarksArray = out; } SharedPreferences.Editor editor = sp.edit(); editor.putString("bookmarks", bookmarksArray.toString()); editor.apply(); } catch (JSONException e) { e.printStackTrace(); } initializeBookmarks(navigationView); }
private void refineInitialEdges(Alignment alignment) { int j = initialEdges.length() - 1; while (j >= 0) { JSONObject initialEdge = initialEdges.getJSONObject(j); String edgeUri = initialEdge.getString(LinkJsonKeys.edgeId.name()); String sourceId = initialEdge.getString(LinkJsonKeys.edgeSourceId.name()); String targetId = initialEdge.getString(LinkJsonKeys.edgeTargetId.name()); String linkId = LinkIdFactory.getLinkId(edgeUri, sourceId, targetId); if (alignment.getLinkById(linkId) == null) { // the link is not even in the graph initialEdges.remove(j); } j--; } }
@Override @SuppressWarnings("unchecked") public void removeProperty(Object obj, Object key) { if (isMap(obj)) toJsonObject(obj).remove(key.toString()); else { JSONArray array = toJsonArray(obj); int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); array.remove(index); } }
public Ason remove(@NotNull String key) { String[] splitKey = splitPath(key); if (splitKey.length == 1) { json.remove(key); } else { Object followed = followPath(json, key, splitKey, false); if (followed == null) { return this; } if (followed instanceof JSONArray) { JSONArray followedArray = (JSONArray) followed; int insertIndex = Integer.parseInt(splitKey[splitKey.length - 1].substring(1)); followedArray.remove(insertIndex); } else { ((JSONObject) followed).remove(splitKey[splitKey.length - 1]); } } return this; }