Skip to content

Commit

Permalink
Merge pull request #41 from dirkx/master
Browse files Browse the repository at this point in the history
Add unsigned long support; addresses issues #39
  • Loading branch information
aentinger committed Oct 27, 2022
2 parents b7904a3 + e8f2289 commit f4e17ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/JSONObject/JSONObject.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <Arduino_JSON.h>
#include <assert.h>

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

Expand Down Expand Up @@ -78,7 +79,19 @@ void demoCreation() {

myObject["hello"] = "world";
myObject["true"] = true;
myObject["x"] = 42;

myObject["x1"] = (int) 42;
myObject["x2"] = (long) 42;
myObject["x3"] = (unsigned long) 42;

int x1 = myObject["x1"];
assert(x1 == 42);

long x2 = myObject["x2"];
assert(x2 == 42);

unsigned long x3 = myObject["x3"];
assert(x3 == 42);

Serial.print("myObject.keys() = ");
Serial.println(myObject.keys());
Expand Down
5 changes: 5 additions & 0 deletions src/JSONVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ JSONVar::operator long() const
return cJSON_IsNumber(_json) ? _json->valueint : 0;
}

JSONVar::operator unsigned long() const
{
return cJSON_IsNumber(_json) ? _json->valueint : 0;
}

JSONVar::operator double() const
{
return cJSON_IsNumber(_json) ? _json->valuedouble : NAN;
Expand Down
1 change: 1 addition & 0 deletions src/JSONVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class JSONVar : public Printable {
operator bool() const;
operator int() const;
operator long() const;
operator unsigned long() const;
operator double() const;
operator const char*() const;

Expand Down

0 comments on commit f4e17ef

Please # to comment.