com.google.gson.JsonArray.remove()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(272)

本文整理了Java中com.google.gson.JsonArray.remove()方法的一些代码示例,展示了JsonArray.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonArray.remove()方法的具体详情如下:
包路径:com.google.gson.JsonArray
类名称:JsonArray
方法名:remove

JsonArray.remove介绍

[英]Removes the element at the specified position in this array. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the array.
[中]删除此数组中指定位置的元素。将任何后续元素向左移动(从其索引中减去一个)。返回从数组中删除的元素。

代码示例

代码示例来源:origin: json-path/JsonPath

@SuppressWarnings("unchecked")
public void removeProperty(final Object obj, final 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.jayway.jsonpath/json-path

@SuppressWarnings("unchecked")
public void removeProperty(final Object obj, final 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: de.unijena.bioinf.ms/io

@Override
public JsonElement deleteFromList(final JsonArray jsonArray, final int index) {
  return jsonArray.remove(index);
}

代码示例来源:origin: Bkm016/TabooLib

/**
 * 移除成员
 *
 * @param obj 成员
 */
public void remove(JsonElement obj) {
  jsonArray.remove(obj);
}

代码示例来源:origin: cloudfoundry-incubator/multiapps-controller

@Override
public void remove(int index) {
  gsonElement.remove(index);
}

代码示例来源:origin: Bkm016/TabooLib

/**
 * 移除成员
 *
 * @param obj 成员
 */
public void remove(Boolean obj) {
  jsonArray.remove(new JsonPrimitive(obj));
}

代码示例来源:origin: Bkm016/TabooLib

/**
 * 移除成员
 *
 * @param obj 成员
 */
public void remove(Number obj) {
  jsonArray.remove(new JsonPrimitive(obj));
}

代码示例来源:origin: Bkm016/TabooLib

/**
 * 移除成员
 *
 * @param obj 成员
 */
public void remove(String obj) {
  jsonArray.remove(new JsonPrimitive(obj));
}

代码示例来源: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}"+
     "]}";
   JsonParser parser = new JsonParser();
   JsonObject json = parser.parse(s).getAsJsonObject();
   System.out.println("original object:"+json);
   JsonArray fieldsObject = json.getAsJsonArray("fields");
   System.out.println("Before removal :"+fieldsObject);
   Object remove = fieldsObject.remove(1);
   System.out.println("After removal :"+fieldsObject);
 }

代码示例来源:origin: stackoverflow.com

JsonArray array = new JsonArray();
array.add(new JsonPrimitive("Red"));
array.add(new JsonPrimitive("Green"));
array.add(new JsonPrimitive("Blue"));

array.remove(2);
array.set(0, new JsonPrimitive("Yelow"));

代码示例来源:origin: org.ballerinalang/language-server-core

private static void stringTemplateSourceFromWS(int currentWs, int nextWs, JsonArray literals, JsonArray ws,
                        int i) {
  if (ws.get(currentWs).getAsJsonObject().get("text").getAsString().contains("{{")) {
    literals.get(i).getAsJsonObject().get("ws").getAsJsonArray().add(ws.get(currentWs));
    literals.get(i).getAsJsonObject().addProperty("value",
        ws.get(currentWs).getAsJsonObject().get("text").getAsString());
    // TODO: use splice
    ws.remove(currentWs);
    literals.get(i).getAsJsonObject().addProperty("startTemplateLiteral", true);
  } else if (ws.get(currentWs).getAsJsonObject().get("text").getAsString().contains("}}")) {
    literals.get(i).getAsJsonObject().get("ws").getAsJsonArray().add(ws.get(currentWs));
    if (ws.get(nextWs).getAsJsonObject().get("text").getAsString().contains("{{")) {
      literals.get(i).getAsJsonObject().get("ws").getAsJsonArray().add(ws.get(nextWs));
      literals.get(i).getAsJsonObject().addProperty("value",
          ws.get(nextWs).getAsJsonObject().get("text").getAsString());
      literals.get(i).getAsJsonObject().addProperty("startTemplateLiteral", true);
      // TODO: use splice
      ws.remove(nextWs);
    }
    // TODO: use splice
    ws.remove(currentWs);
    literals.get(i).getAsJsonObject().addProperty("endTemplateLiteral", true);
  }
}

代码示例来源:origin: org.ballerinalang/language-server-core

private static void literalWSAssignForTemplates(int currentWs, int nextWs,
                        JsonArray literals, JsonArray ws, int wsStartLocation) {
  if (literals.size() == (ws.size() - wsStartLocation)) {
    for (int i = 0; i < literals.size(); i++) {
      if (literals.get(i).getAsJsonObject().get("kind").getAsString().equals("Literal")) {
        if (!literals.get(i).getAsJsonObject().has("ws")) {
          literals.get(i).getAsJsonObject().add("ws", new JsonArray());
        }
        stringTemplateSourceFromWS(currentWs, nextWs, literals, ws, i);
        if (i == (literals.size() - 1)) {
          literals.get(i).getAsJsonObject().get("ws").getAsJsonArray().add(ws.get(currentWs));
          literals.get(i).getAsJsonObject().addProperty("value",
              ws.get(currentWs).getAsJsonObject().get("text").getAsString());
          literals.get(i).getAsJsonObject().addProperty("lastNodeValue", true);
          // TODO: use splice.
          ws.remove(currentWs);
        }
      }
    }
  } else if ((literals.size() - 1) == (ws.size() - wsStartLocation)) {
    for (int i = 0; i < literals.size(); i++) {
      if (literals.get(i).getAsJsonObject().get("kind").getAsString().equals("Literal")) {
        if (!literals.get(i).getAsJsonObject().has("ws")) {
          literals.get(i).getAsJsonObject().add("ws", new JsonArray());
        }
        stringTemplateSourceFromWS(currentWs, nextWs, literals, ws, i);
      }
    }
  }
}

代码示例来源:origin: antest1/kcanotify

public void updateQuestCheck(int tab, JsonObject data) {
  String tab_key = String.valueOf(tab);
  JsonObject q_data = getJsonObjectValue(DB_KEY_QUESTNCHK);
  if (q_data == null) q_data = initQuestCheck();
  if (!q_data.getAsJsonObject("total").has(tab_key)) {
    q_data.getAsJsonObject("total").addProperty(tab_key, 0);
    q_data.getAsJsonObject("count").add(tab_key, new JsonArray());
  }
  int page_count = data.get("api_page_count").getAsInt();
  int disp_page = data.get("api_disp_page").getAsInt();
  q_data.getAsJsonObject("total").addProperty(tab_key, page_count);
  JsonArray count_list = q_data.getAsJsonObject("count").getAsJsonArray(tab_key);
  if (disp_page > page_count) {
    count_list.remove(new JsonPrimitive(disp_page));
  } else if (!count_list.contains(new JsonPrimitive(disp_page))) {
    count_list.add(disp_page);
  }
  putValue(DB_KEY_QUESTNCHK, q_data.toString());
}

代码示例来源:origin: org.ballerinalang/language-server-core

&& childItem.getAsJsonObject().has("lambda")
    && childItem.getAsJsonObject().get("lambda").getAsBoolean()) {
  childArray.remove(j);
  j--;
} else if (childItem.isJsonObject()

代码示例来源:origin: com.github.lafa.jsonpath/json-path

@Override
@SuppressWarnings("unchecked")
public void removeProperty(final Object obj, final 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: net.riotopsys/json_patch

@Override
  public JsonElement apply(JsonElement original) {
    JsonElement result = duplicate( original );

    JsonElement item = path.head().navigate(result);

    if ( item.isJsonObject() ){
//            Map<String, JsonElement> map = getBackingMap(item.getAsJsonObject());

//            map.remove(path.tail());

      item.getAsJsonObject().remove(path.tail());

    } else if ( item.isJsonArray() ){

      JsonArray array = item.getAsJsonArray();

      int index = (path.tail().equals("-")) ? array.size() : Integer.valueOf(path.tail());

      array.remove(index);

    }

    return result;
  }
}

代码示例来源:origin: antest1/kcanotify

JsonPrimitive pkg = new JsonPrimitive(package_name);
if (data.contains(pkg)) {
  data.remove(pkg);
  holder.nameView.setTextColor(ContextCompat.getColor(context,getCheckedTextColor(false)));

代码示例来源:origin: org.ballerinalang/language-server-core

int firstTokenIndex = matchedObjWS.get(0).get("i").getAsInt();
    targetResourceInfoOperation
        .remove(matchedKeyValuePairIndex);
    FormattingSourceGen.reconcileWS(sourceKeyValue, targetResourceInfoOperation,
        tree, firstTokenIndex);
int firstTokenIndex = matchedObjWS.get(0).get("i").getAsInt();
matchedTargetRecord.getAsJsonArray("keyValuePairs")
    .remove(matchedKeyValuePairIndex);
FormattingSourceGen.reconcileWS(sourceKeyValue, matchedTargetRecord
    .getAsJsonArray("keyValuePairs"), tree, firstTokenIndex);

代码示例来源:origin: net.riotopsys/json_patch

array.remove(index);

代码示例来源:origin: stackoverflow.com

testsets.remove(tsJsonObject);
JsonObject testCaseUpdate = new JsonObject();
testCaseUpdate.add("TestSets", testsets);

相关文章