mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Added a test that adds a empty nested array in an array
This commit is contained in:
@ -38,6 +38,13 @@ public:
|
|||||||
addItem(JSON_BOOLEAN, v);
|
addItem(JSON_BOOLEAN, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(JsonObjectBase& value)
|
||||||
|
{
|
||||||
|
JsonObjectValue v;
|
||||||
|
v.object = &value;
|
||||||
|
addItem(JSON_OBJECT, v);
|
||||||
|
}
|
||||||
|
|
||||||
void writeTo(char* buffer, size_t bufferSize)
|
void writeTo(char* buffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
StringBuilder sb(buffer, bufferSize);
|
StringBuilder sb(buffer, bufferSize);
|
||||||
|
@ -102,18 +102,15 @@ namespace JsonGeneratorTests
|
|||||||
AssertJsonIs("[false,true]");
|
AssertJsonIs("[false,true]");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
TEST_METHOD(AddOneEmptyNestedArray)
|
TEST_METHOD(AddOneEmptyNestedArray)
|
||||||
{
|
{
|
||||||
JsonArray<0> nestedArray;
|
JsonArray<1> nestedArray;
|
||||||
|
|
||||||
arr.add(nestedArray);
|
arr.add(nestedArray);
|
||||||
|
|
||||||
AssertJsonIs("[[]]");
|
AssertJsonIs("[[]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
void AssertJsonIs(const char* expected)
|
void AssertJsonIs(const char* expected)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
@ -21,13 +21,15 @@ protected:
|
|||||||
JSON_STRING,
|
JSON_STRING,
|
||||||
JSON_NUMBER,
|
JSON_NUMBER,
|
||||||
JSON_BOOLEAN,
|
JSON_BOOLEAN,
|
||||||
|
JSON_OBJECT,
|
||||||
};
|
};
|
||||||
|
|
||||||
union JsonObjectValue
|
union JsonObjectValue
|
||||||
{
|
{
|
||||||
const char* string;
|
const char* string;
|
||||||
double number;
|
double number;
|
||||||
bool boolean;
|
bool boolean;
|
||||||
|
JsonObjectBase* object;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JsonObject
|
struct JsonObject
|
||||||
@ -36,7 +38,7 @@ protected:
|
|||||||
JsonObjectValue value;
|
JsonObjectValue value;
|
||||||
};
|
};
|
||||||
|
|
||||||
void writeObjectTo(const JsonObject& obj, StringBuilder& sb)
|
void writeObjectTo(JsonObject& obj, StringBuilder& sb)
|
||||||
{
|
{
|
||||||
switch (obj.type)
|
switch (obj.type)
|
||||||
{
|
{
|
||||||
@ -54,6 +56,13 @@ protected:
|
|||||||
case JSON_BOOLEAN:
|
case JSON_BOOLEAN:
|
||||||
sb.append(obj.value.boolean ? "true" : "false");
|
sb.append(obj.value.boolean ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case JSON_OBJECT:
|
||||||
|
if (obj.value.object)
|
||||||
|
obj.value.object->writeTo(sb);
|
||||||
|
else
|
||||||
|
sb.append("null");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user