首页 > 文档 > loadJSONArray()读取数据库文件数组
2017
07-14

loadJSONArray()读取数据库文件数组

3-6.loadJSONArray()

Name(名称):loadJSONArray()//读取数据库文件数组

Examples(例子):

// The following short JSON file called “data.json” is parsed以下称为”data.json”的简短JSON文件被解析

// 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”);

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:

// 0, Capra hircus, Goat

// 1, Panthera pardus, Leopard

// 2, Equus zebra, Zebra

Description(描述):Loads an array of JSON objects from the data folder or a URL, and returns a JSONArray. Per standard JSON syntax, the array must be enclosed in a pair of hard brackets [], and each object within the array must be separated by a comma.

从数据文件夹或URL中加载一组JSON对象,并返回一个JSONArray。 按照标准的JSON语法,数组必须用一对硬括号[]括起来,数组中的每个对象必须用逗号分隔。

All files loaded and saved by the Processing API use UTF-8 encoding.

Processing API加载和保存的所有文件都使用UTF-8编码。

Syntax(语法):loadJSONArray(filename)

loadJSONArray(file)

Parameters (参数):filename——name of a file in the data folder or a URL数据文件夹中的文件名或URL

Returns(返回值):JSONArray

Related(相关函数):JSONArray
loadJSONObject()
saveJSONObject()
saveJSONArray()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。