本文整理了Java中org.json.JSONArray.remove()
方法的一些代码示例,展示了JSONArray.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.remove()
方法的具体详情如下:
包路径:org.json.JSONArray
类名称:JSONArray
方法名:remove
[英]Removes and returns the value at index, or null if the array has no value at index.
[中]移除并返回索引处的值,如果数组在索引处没有值,则返回null。
代码示例来源:origin: json-path/JsonPath
@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);
}
}
代码示例来源:origin: loklak/loklak_server
messages.remove(i);
nodePushReport.incrementKnownCount(existed);
continue;
代码示例来源:origin: com.jayway.jsonpath/json-path
@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);
}
}
代码示例来源:origin: yacy/yacy_grid_mcp
public Action removeNextAction() {
JSONArray a = getActionsJSON();
if (a.length() == 0) return null;
return new Action((JSONObject) this.getJSONArray(KEY_ACTIONS).remove(0));
}
代码示例来源:origin: denzilferreira/aware-client
public ESMFactory removeESM(int position) {
queue.remove(position);
return this;
}
代码示例来源:origin: com.afollestad/ason
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;
}
代码示例来源:origin: stackoverflow.com
JSONArray jArray = new JSONArray();
jArray.remove(position); // For remove JSONArrayElement
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: ca.carleton.gcrc/nunaliit2-couch-client
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);
}
}
}
代码示例来源:origin: stackoverflow.com
JSONObject root = new JSONObject(json);
JSONArray myData = (JSONArray) root.get("myData");
myData.remove(0);
myData.put(4);
System.out.println("root = " + root.toString());
代码示例来源:origin: stackoverflow.com
//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");
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: stackoverflow.com
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);
}
}
代码示例来源:origin: org.visallo/visallo-core
public static void removeFromJSONArray(JSONArray jsonArray, Object value) {
int idx = arrayIndexOf(jsonArray, value);
if (idx >= 0) {
jsonArray.remove(idx);
}
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: PortSwigger/replicator
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);
}
代码示例来源:origin: martykan/webTube
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);
}
代码示例来源:origin: usc-isi-i2/Web-Karma
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--;
}
}
代码示例来源:origin: com.github.lafa.jsonpath/json-path
@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);
}
}
代码示例来源:origin: com.afollestad/ason
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;
}
内容来源于网络,如有侵权,请联系作者删除!