mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Serialize integer values in object
This commit is contained in:
@ -28,7 +28,7 @@ struct JsonNode
|
||||
{
|
||||
bool asBoolean;
|
||||
double asDouble;
|
||||
int asInteger;
|
||||
long asInteger;
|
||||
const char* asString;
|
||||
|
||||
struct
|
||||
|
@ -108,11 +108,21 @@ size_t JsonObject::printTo(Print& p) const
|
||||
for (JsonNode* child = firstChild; child; child = child->next)
|
||||
{
|
||||
const char* childKey = child->content.asKey.key;
|
||||
const char* childValue = child->content.asKey.value->content.asString;
|
||||
JsonNode* childValue = child->content.asKey.value;
|
||||
|
||||
n += EscapedString::printTo(childKey, p);
|
||||
n += p.write(':');
|
||||
n += EscapedString::printTo(childValue, p);
|
||||
|
||||
switch (childValue->type)
|
||||
{
|
||||
case JSON_STRING:
|
||||
n += EscapedString::printTo(childValue->content.asString, p);
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
n += p.print(childValue->content.asInteger);
|
||||
break;
|
||||
}
|
||||
|
||||
if (child->next)
|
||||
{
|
||||
|
@ -89,13 +89,13 @@ TEST_F(JsonObjectSerializationTests, OneStringOverCapacity)
|
||||
|
||||
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
}
|
||||
/*
|
||||
|
||||
TEST_F(JsonObjectSerializationTests, OneInteger)
|
||||
{
|
||||
object["key"] = 1;
|
||||
outputMustBe("{\"key\":1}");
|
||||
}
|
||||
|
||||
/*
|
||||
TEST_F(JsonObjectSerializationTests, OneDoubleFourDigits)
|
||||
{
|
||||
object["key"].set<4>(3.14159265358979323846);
|
||||
|
Reference in New Issue
Block a user