Skip to content

Commit f4e17ef

Browse files
authored
Merge pull request #41 from dirkx/master
Add unsigned long support; addresses issues #39
2 parents b7904a3 + e8f2289 commit f4e17ef

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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());

src/JSONVar.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ JSONVar::operator long() const
142142
return cJSON_IsNumber(_json) ? _json->valueint : 0;
143143
}
144144

145+
JSONVar::operator unsigned long() const
146+
{
147+
return cJSON_IsNumber(_json) ? _json->valueint : 0;
148+
}
149+
145150
JSONVar::operator double() const
146151
{
147152
return cJSON_IsNumber(_json) ? _json->valuedouble : NAN;

src/JSONVar.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class JSONVar : public Printable {
4949
operator bool() const;
5050
operator int() const;
5151
operator long() const;
52+
operator unsigned long() const;
5253
operator double() const;
5354
operator const char*() const;
5455

0 commit comments

Comments
 (0)