Skip to content

Commit 0703318

Browse files
committed
Add unsigned long support; addresses issues arduino-libraries#39
1 parent b7904a3 commit 0703318

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

examples/JSONObject/JSONObject.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ void demoCreation() {
7878

7979
myObject["hello"] = "world";
8080
myObject["true"] = true;
81-
myObject["x"] = 42;
81+
82+
myObject["x1"] = (int) 42;
83+
myObject["x2"] = (long) 42;
84+
myObject["x3"] = (unsigned long) 42;
85+
86+
int x1 = myObject["x1"];
87+
long x2 = myObject["x2"];
88+
unsigned long x3 = myObject["x3"];
8289

8390
Serial.print("myObject.keys() = ");
8491
Serial.println(myObject.keys());

src/JSONVar.cpp

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)