Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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