mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
JsonArray: extracted methods addItem
This commit is contained in:
@ -40,29 +40,23 @@ public:
|
|||||||
|
|
||||||
void add(const char* value)
|
void add(const char* value)
|
||||||
{
|
{
|
||||||
if (itemCount >= N) return;
|
JsonObjectValue v;
|
||||||
|
v.string = value;
|
||||||
items[itemCount].type = JSON_STRING;
|
addItem(JSON_STRING, v);
|
||||||
items[itemCount].value.string = value;
|
|
||||||
itemCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(double value)
|
void add(double value)
|
||||||
{
|
{
|
||||||
if (itemCount >= N) return;
|
JsonObjectValue v;
|
||||||
|
v.number = value;
|
||||||
items[itemCount].type = JSON_NUMBER;
|
addItem(JSON_NUMBER, v);
|
||||||
items[itemCount].value.number = value;
|
|
||||||
itemCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(bool value)
|
void add(bool value)
|
||||||
{
|
{
|
||||||
if (itemCount >= N) return;
|
JsonObjectValue v;
|
||||||
|
v.boolean = value;
|
||||||
items[itemCount].type = JSON_BOOLEAN;
|
addItem(JSON_BOOLEAN, v);
|
||||||
items[itemCount].value.boolean = value;
|
|
||||||
itemCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeTo(char* buffer, size_t bufferSize)
|
void writeTo(char* buffer, size_t bufferSize)
|
||||||
@ -107,5 +101,14 @@ private:
|
|||||||
|
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addItem(JsonObjectType type, JsonObjectValue value)
|
||||||
|
{
|
||||||
|
if (itemCount >= N) return;
|
||||||
|
|
||||||
|
items[itemCount].type = type;
|
||||||
|
items[itemCount].value = value;
|
||||||
|
itemCount++;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,6 +102,18 @@ namespace JsonGeneratorTests
|
|||||||
AssertJsonIs("[false,true]");
|
AssertJsonIs("[false,true]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
TEST_METHOD(AddOneEmptyNestedArray)
|
||||||
|
{
|
||||||
|
JsonArray<0> nestedArray;
|
||||||
|
|
||||||
|
arr.add(nestedArray);
|
||||||
|
|
||||||
|
AssertJsonIs("[[]]");
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
void AssertJsonIs(const char* expected)
|
void AssertJsonIs(const char* expected)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
Reference in New Issue
Block a user