当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Processing JSONArray.remove()用法及代码示例


Processing, 类JSONArray中的remove()用法介绍。

用法

  • .remove(index)

参数

  • index (int) 要移除的元素的索引值

返回

  • Object

说明

从指定索引位置的JSONArray 中删除元素。返回与给定索引关联的值,如果没有值,则返回 null

例子

// The following short JSON file called "data.json" is parsed 
// in the code below. It must be in the project's "data" folder.
//
// [
//   {
//     "id": 0,
//     "species": "Capra hircus",
//     "name": "Goat"
//   },
//   {
//     "id": 1,
//     "species": "Panthera pardus",
//     "name": "Leopard"
//   },
//   {
//     "id": 2,
//     "species": "Equus zebra",
//     "name": "Zebra"
//   }
// ]

JSONArray values;

void setup() {

  values = loadJSONArray("data.json");

  values.remove(0);  // Remove the array's first element

  for (int i = 0; i < values.size(); i++) {
    
    JSONObject animal = values.getJSONObject(i); 

    int id = animal.getInt("id");
    String species = animal.getString("species");
    String name = animal.getString("name");

    println(id + ", " + species + ", " + name);
  }
}

// Sketch prints:
// 1, Panthera pardus, Leopard
// 2, Equus zebra, Zebra

相关用法


注:本文由纯净天空筛选整理自processing.org大神的英文原创作品 JSONArray.remove()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。