-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathJSONArray_getJSONObject.xml
More file actions
executable file
·65 lines (50 loc) · 1.2 KB
/
JSONArray_getJSONObject.xml
File metadata and controls
executable file
·65 lines (50 loc) · 1.2 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
63
64
65
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>getJSONObject()</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.
//
// [
// {
// "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
]]></code>
</example>
<description><![CDATA[
Retrieves the <b>JSONObject</b> with the associated index value.
]]></description>
</root>