Skip to content

Commit 53ed894

Browse files
authored
Merge branch 'master' into master
2 parents 5bccd3d + ef9cb84 commit 53ed894

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

.github/workflows/sync-labels.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
- name: Download JSON schema for labels configuration file
3333
id: download-schema
34-
uses: carlosperate/download-file-action@v1
34+
uses: carlosperate/download-file-action@v2
3535
with:
3636
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json
3737
location: ${{ runner.temp }}/label-configuration-schema
@@ -65,7 +65,7 @@ jobs:
6565

6666
steps:
6767
- name: Download
68-
uses: carlosperate/download-file-action@v1
68+
uses: carlosperate/download-file-action@v2
6969
with:
7070
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
7171

examples/JSONObject/JSONObject.ino

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <Arduino_JSON.h>
11+
#include <assert.h>
1112

1213
const char input[] = "{\"result\":true,\"count\":42,\"foo\":\"bar\"}";
1314

@@ -78,7 +79,19 @@ void demoCreation() {
7879

7980
myObject["hello"] = "world";
8081
myObject["true"] = true;
81-
myObject["x"] = 42;
82+
83+
myObject["x1"] = (int) 42;
84+
myObject["x2"] = (long) 42;
85+
myObject["x3"] = (unsigned long) 42;
86+
87+
int x1 = myObject["x1"];
88+
assert(x1 == 42);
89+
90+
long x2 = myObject["x2"];
91+
assert(x2 == 42);
92+
93+
unsigned long x3 = myObject["x3"];
94+
assert(x3 == 42);
8295

8396
Serial.print("myObject.keys() = ");
8497
Serial.println(myObject.keys());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
JSON Value Extractor
3+
4+
This sketch demonstrates how to use some features
5+
of the Official Arduino JSON library to traverse through all the
6+
key value pair in the object and the nested objects.
7+
Can be very helpful when searching for a specific data in a key
8+
which is nested at multiple levels
9+
The sketch actually use recursion to traverse all the keys in
10+
a given JSON.
11+
12+
Example originally added on 24-03-2020
13+
by Madhur Dixit https://github.com/Chester-King
14+
15+
This example code is in the public domain.
16+
*/
17+
18+
#include <Arduino_JSON.h>
19+
20+
void setup() {
21+
22+
Serial.begin(9600);
23+
while (!Serial);
24+
valueExtractor();
25+
26+
}
27+
28+
void loop() {
29+
}
30+
31+
void valueExtractor() {
32+
33+
Serial.println("object");
34+
Serial.println("======");
35+
JSONVar myObject;
36+
37+
// Making a JSON Object
38+
myObject["foo"] = "bar";
39+
myObject["blah"]["abc"] = 42;
40+
myObject["blah"]["efg"] = "pod";
41+
myObject["blah"]["cde"]["pan1"] = "King";
42+
myObject["blah"]["cde"]["pan2"] = 3.14;
43+
myObject["jok"]["hij"] = "bar";
44+
45+
Serial.println(myObject);
46+
Serial.println();
47+
Serial.println("Extracted Values");
48+
Serial.println("======");
49+
50+
objRec(myObject);
51+
52+
}
53+
54+
void objRec(JSONVar myObject) {
55+
Serial.println("{");
56+
for (int x = 0; x < myObject.keys().length(); x++) {
57+
if ((JSON.typeof(myObject[myObject.keys()[x]])).equals("object")) {
58+
Serial.print(myObject.keys()[x]);
59+
Serial.println(" : ");
60+
objRec(myObject[myObject.keys()[x]]);
61+
}
62+
else {
63+
Serial.print(myObject.keys()[x]);
64+
Serial.print(" : ");
65+
Serial.println(myObject[myObject.keys()[x]]);
66+
}
67+
}
68+
Serial.println("}");
69+
}

src/JSONVar.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ JSONVar::operator unsigned long () const
202202
return cJSON_IsNumber (_json) ? _json->valueint : 0;
203203
}
204204

205+
JSONVar::operator unsigned long() const
206+
{
207+
return cJSON_IsNumber(_json) ? _json->valueint : 0;
208+
}
209+
205210
JSONVar::operator double() const
206211
{
207212
return cJSON_IsNumber(_json) ? _json->valuedouble : NAN;

0 commit comments

Comments
 (0)