首页 > 文档 > JSONArray JSON数组
2017
07-17

JSONArray JSON数组

Name

JSONArray JSON数组

Examples

String[] species = { “Capra hircus”, “Panthera pardus”, “Equus zebra” };

String[] names = { “Goat”, “Leopard”, “Zebra” };

 

JSONArray values;

 

void setup() {

 

values = new JSONArray();

 

for (int i = 0; i < species.length; i++) {

 

JSONObject animal = new JSONObject();

 

animal.setInt(“id”, i);

animal.setString(“species”, species[i]);

animal.setString(“name”, names[i]);

 

values.setJSONObject(i, animal);

}

 

saveJSONArray(values, “data/new.json”);

}

 

// Sketch saves the following to a file called “new.json”:

// [

// {

// “id”: 0,

// “species”: “Capra hircus”,

// “name”: “Goat”

// },

// {

// “id”: 1,

// “species”: “Panthera pardus”,

// “name”: “Leopard”

// },

// {

// “id”: 2,

// “species”: “Equus zebra”,

// “name”: “Zebra”

// }

// ]

Description

JSONArray stores an array of JSON objects. JSONArrays can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk, as in the example above.

JSONArray 存储一个 json 对象数组。JSONArrays 可以从头开始、动态地或使用现有文件中的数据生成。json 也可以输出并保存到磁盘上, 如上面的示例中所示。

Methods

getString()

Gets the String value associated with an index获取与索引关联的字符串值

getInt()

Gets the int value associated with an index获取与索引关联的整值

getFloat()

Gets the float value associated with an index获取与索引关联的浮点值

getBoolean()

Gets the boolean value associated with an index获取与索引关联的布尔值

getJSONArray()

Gets the JSONArray associated with an index value获取与索引值关联的 JSONArray

getJSONObject()

Gets the JSONObject associated with an index value获取与索引值关联的 JSONObject

getStringArray()

Gets the entire array as an array of Strings以字符串数组的形式获取整个数组

getIntArray()

Gets the entire array as array of ints以整数数组的形式获取整个数组

append()

Appends a value, increasing the array’s length by one追加一个值, 将数组的长度增加一个

setString()

Put a String value in the JSONArray jsonarray 中设置一个字符串值

setInt()

Put an int value in the JSONArray jsonarray 中放置一个 int

setFloat()

Put a float value in the JSONArray

setBoolean()

Put a boolean value in the JSONArray

setJSONArray()

Sets the JSONArray value associated with an index value

setJSONObject()

Sets the JSONObject value associated with an index value

size()

Gets the number of elements in the JSONArray获取数量

isNull()

Determine if the value is null.是不是空的

remove()

Removes an element移除

Constructor

JSONArray()

Related

JSONObject
loadJSONObject()
loadJSONArray()
saveJSONObject()
saveJSONArray()

Updated on April 30, 2017 02:33:20pm EDT



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

留下一个回复

你的email不会被公开。