Processing, 類JSONObject
中的getJSONArray()
用法介紹。
用法
.getJSONArray(key)
參數
key
(String)
一個關鍵字符串
返回
JSONArray
說明
檢索帶有關聯 key 的JSONArray
。
例子
// The following short JSON file called "data.json" is parsed
// in the code below. It must be in the project's "data" folder.
//
// { "animals": [
// {
// "id": 0,
// "species": "Capra hircus",
// "name": "Goat"
// },
// {
// "id": 1,
// "species": "Panthera pardus",
// "name": "Leopard"
// },
// {
// "id": 2,
// "species": "Equus zebra",
// "name": "Zebra"
// } ]
// }
JSONObject json;
void setup() {
json = loadJSONObject("data.json");
JSONArray values = json.getJSONArray("animals");
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
相關用法
- Processing JSONObject.getJSONObject()用法及代碼示例
- Processing JSONObject.getString()用法及代碼示例
- Processing JSONObject.getFloat()用法及代碼示例
- Processing JSONObject.getBoolean()用法及代碼示例
- Processing JSONObject.getInt()用法及代碼示例
- Processing JSONObject.setJSONArray()用法及代碼示例
- Processing JSONObject.isNull()用法及代碼示例
- Processing JSONObject.setString()用法及代碼示例
- Processing JSONObject.setJSONObject()用法及代碼示例
- Processing JSONObject.setInt()用法及代碼示例
- Processing JSONObject.setFloat()用法及代碼示例
- Processing JSONObject.setBoolean()用法及代碼示例
- Processing JSONObject用法及代碼示例
- Processing JSONArray.getIntArray()用法及代碼示例
- Processing JSONArray.getFloat()用法及代碼示例
- Processing JSONArray.setString()用法及代碼示例
- Processing JSONArray.setFloat()用法及代碼示例
- Processing JSONArray.remove()用法及代碼示例
- Processing JSONArray.getString()用法及代碼示例
- Processing JSONArray.setBoolean()用法及代碼示例
- Processing JSONArray.getJSONArray()用法及代碼示例
- Processing JSONArray.setJSONObject()用法及代碼示例
- Processing JSONArray.getJSONObject()用法及代碼示例
- Processing JSONArray.size()用法及代碼示例
- Processing JSONArray.isNull()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 JSONObject.getJSONArray()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。