mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 13:02:25 +02:00
Fixed bug in JsonArray::begin() and end()
This commit is contained in:
@ -35,19 +35,19 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
int size()
|
int size()
|
||||||
{
|
{
|
||||||
return isArray() ? JsonToken::size() : 0;
|
return isArray() ? childrenCount() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue operator[](int index);
|
JsonValue operator[](int index);
|
||||||
|
|
||||||
JsonArrayIterator begin()
|
JsonArrayIterator begin()
|
||||||
{
|
{
|
||||||
return firstChild();
|
return isArray() ? firstChild() : null();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArrayIterator end()
|
JsonArrayIterator end()
|
||||||
{
|
{
|
||||||
return nextSibling();
|
return isArray() ? nextSibling() : null();
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED int getLength()
|
DEPRECATED int getLength()
|
||||||
|
@ -28,7 +28,7 @@ JsonValue JsonObject::operator[](const char* desiredKey)
|
|||||||
JsonToken runningToken = firstChild();
|
JsonToken runningToken = firstChild();
|
||||||
|
|
||||||
// scan each keys
|
// scan each keys
|
||||||
for (int i = 0; i < size() / 2; i++)
|
for (int i = 0; i < childrenCount() / 2; i++)
|
||||||
{
|
{
|
||||||
// get 'key' token string
|
// get 'key' token string
|
||||||
char* key = runningToken.getText();
|
char* key = runningToken.getText();
|
||||||
|
@ -75,7 +75,7 @@ namespace ArduinoJson
|
|||||||
return token != 0 && token->type == JSMN_STRING;
|
return token != 0 && token->type == JSMN_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size()
|
int childrenCount()
|
||||||
{
|
{
|
||||||
return token->size;
|
return token->size;
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,30 @@ namespace JsonParserTests
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
TEST_METHOD(EmptyJson)
|
||||||
|
{
|
||||||
|
char json[] = "";
|
||||||
|
JsonParser<1> parser;
|
||||||
|
|
||||||
|
JsonArray a = parser.parse(json);
|
||||||
|
|
||||||
|
int loopCount = 0;
|
||||||
|
|
||||||
|
for (long i : a)
|
||||||
|
{
|
||||||
|
loopCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::AreEqual(0, loopCount);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_METHOD(ThreeIntegers)
|
TEST_METHOD(ThreeIntegers)
|
||||||
{
|
{
|
||||||
char json [] = "[1,2,3]";
|
char json [] = "[1,2,3]";
|
||||||
long expected [] = { 1, 2, 3 };
|
long expected [] = { 1, 2, 3 };
|
||||||
JsonParser<4> parser;
|
JsonParser<4> parser;
|
||||||
|
|
||||||
JsonValue v = parser.parse(json);
|
JsonArray a = parser.parse(json);
|
||||||
JsonArray a = (ArduinoJson::Parser::JsonArray)v;
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -27,6 +43,5 @@ namespace JsonParserTests
|
|||||||
Assert::AreEqual(expected[index++], i);
|
Assert::AreEqual(expected[index++], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
Reference in New Issue
Block a user