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


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


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

用法

  • .getInt(index)
  • .getInt(index, defaultValue)

参数

  • index (int) 必须介于 0 和 length() - 1 之间
  • index (int) 索引必须介于 0 和 length() - 1 之间。
  • defaultValue (int) 默认值。

返回

  • int

说明

获取与指定索引关联的int 值。

例子

// The following short JSON file called "data.json" is parsed 
// in the code below. It must be in the project's "data" folder.
//
// [ 32, 1.13, "grape", true ]

JSONArray json;

void setup() {

  json = loadJSONArray("data.json");

  int count = json.getInt(0);
  float weight = json.getFloat(1);
  String name = json.getString(2);
  boolean isFruit = json.getBoolean(3);

  println(count + ", " + weight + ", " + name + ", " + isFruit);
}

// Sketch prints:
// 32, 1.13, grape, true

相关用法


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