-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathJSONArray_getJSONArray.xml
More file actions
executable file
·62 lines (46 loc) · 1.23 KB
/
JSONArray_getJSONArray.xml
File metadata and controls
executable file
·62 lines (46 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>getJSONArray()</name>
<category>JSONArray</category>
<subcategory>Method</subcategory>
<type>method</type>
<example>
<image></image>
<code><![CDATA[
// The following short JSON file called "data.json" is parsed
// in the code below. It must be in the project's "data" folder.
//
// [
// [
// { "name": "apple", "isFruit": true },
// { "name": "grape", "isFruit": true },
// { "name": "carrot", "isFruit": false }
// ],
// [
// { "name": "lettuce", "isFruit": false },
// { "name": "plum", "isFruit": true },
// { "name": "cinnamon", "isFruit": false }
// ]
// ]
JSONArray json;
void setup() {
json = loadJSONArray("data.json");
// Get the first array of elements
JSONArray values = json.getJSONArray(0);
for (int i = 0; i < values.size(); i++) {
JSONObject item = values.getJSONObject(i);
String name = item.getString("name");
boolean isFruit = item.getBoolean("isFruit");
println(name + ", " + isFruit);
}
}
// Sketch prints:
// apple, true
// grape, true
// carrot, false
]]></code>
</example>
<description><![CDATA[
Retrieves the <b>JSONArray</b> with the associated index value.
]]></description>
</root>