diff --git a/JsonParser/JsonObject.h b/JsonParser/JsonObject.h
index e807f3ba..6f6e1937 100644
--- a/JsonParser/JsonObject.h
+++ b/JsonParser/JsonObject.h
@@ -42,12 +42,12 @@ namespace ArduinoJson
JsonObjectIterator begin()
{
- return firstChild();
+ return isObject() ? firstChild() : null();
}
JsonObjectIterator end()
{
- return nextSibling();
+ return isObject() ? nextSibling() : null();
}
DEPRECATED JsonArray getArray(const char* key);
diff --git a/JsonParserTests/JsonArrayIteratorTests.cpp b/JsonParserTests/JsonArrayIteratorTests.cpp
index 919e5cc6..94e0349e 100644
--- a/JsonParserTests/JsonArrayIteratorTests.cpp
+++ b/JsonParserTests/JsonArrayIteratorTests.cpp
@@ -7,28 +7,26 @@ using namespace ArduinoJson::Parser;
namespace JsonParserTests
{
- TEST_CLASS(JsonObjectIteratorTests)
- {
- public:
+ TEST_CLASS(JsonArrayIteratorTests)
+ {
+ public:
+
+ TEST_METHOD(ThreeIntegers)
+ {
+ char json [] = "[1,2,3]";
+ long expected [] = { 1, 2, 3 };
+ JsonParser<4> parser;
- TEST_METHOD(ThreeStrings)
- {
- char json [] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
- char* expectedKeys [] = { "key1", "key2", "key3" };
- char* expectedValues [] = { "value1", "value2", "value3" };
- JsonParser<7> parser;
-
- JsonHashTable a = parser.parse(json);
+ JsonValue v = parser.parse(json);
+ JsonArray a = (ArduinoJson::Parser::JsonArray)v;
int index = 0;
- for (auto i : a)
+ for (long i : a)
{
- Assert::AreEqual(expectedKeys[index], i.key());
- Assert::AreEqual(expectedValues[index], (const char*) i.value());
- index++;
+ Assert::AreEqual(expected[index++], i);
}
- }
+ }
- };
+ };
}
\ No newline at end of file
diff --git a/JsonParserTests/JsonObjectIteratorTests.cpp b/JsonParserTests/JsonObjectIteratorTests.cpp
index 94e0349e..9acbf41a 100644
--- a/JsonParserTests/JsonObjectIteratorTests.cpp
+++ b/JsonParserTests/JsonObjectIteratorTests.cpp
@@ -7,26 +7,62 @@ using namespace ArduinoJson::Parser;
namespace JsonParserTests
{
- TEST_CLASS(JsonArrayIteratorTests)
- {
- public:
-
- TEST_METHOD(ThreeIntegers)
- {
- char json [] = "[1,2,3]";
- long expected [] = { 1, 2, 3 };
- JsonParser<4> parser;
+ TEST_CLASS(JsonObjectIteratorTests)
+ {
+ public:
- JsonValue v = parser.parse(json);
- JsonArray a = (ArduinoJson::Parser::JsonArray)v;
+ TEST_METHOD(EmptyObject)
+ {
+ char json [] = "{}";
+ JsonParser<1> parser;
+
+ JsonHashTable a = parser.parse(json);
+
+ int loopCount = 0;
+
+ for (auto i : a)
+ {
+ loopCount++;
+ }
+
+ Assert::AreEqual(0, loopCount);
+ }
+
+ TEST_METHOD(EmptyJson)
+ {
+ char json[] = "";
+ JsonParser<1> parser;
+
+ JsonHashTable a = parser.parse(json);
+
+ int loopCount = 0;
+
+ for (auto i : a)
+ {
+ loopCount++;
+ }
+
+ Assert::AreEqual(0, loopCount);
+ }
+
+ TEST_METHOD(ThreeStrings)
+ {
+ char json[] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
+ char* expectedKeys[] = { "key1", "key2", "key3" };
+ char* expectedValues[] = { "value1", "value2", "value3" };
+ JsonParser<7> parser;
+
+ JsonHashTable a = parser.parse(json);
int index = 0;
- for (long i : a)
+ for (auto i : a)
{
- Assert::AreEqual(expected[index++], i);
+ Assert::AreEqual(expectedKeys[index], i.key());
+ Assert::AreEqual(expectedValues[index], (const char*) i.value());
+ index++;
}
- }
+ }
- };
+ };
}
\ No newline at end of file
diff --git a/JsonParserTests/JsonParserTests.vcxproj b/JsonParserTests/JsonParserTests.vcxproj
index 75f5ab83..3656b96c 100644
--- a/JsonParserTests/JsonParserTests.vcxproj
+++ b/JsonParserTests/JsonParserTests.vcxproj
@@ -91,9 +91,9 @@
-
-
+
+
diff --git a/JsonParserTests/JsonParserTests.vcxproj.filters b/JsonParserTests/JsonParserTests.vcxproj.filters
index 9291f4d1..fcdfd493 100644
--- a/JsonParserTests/JsonParserTests.vcxproj.filters
+++ b/JsonParserTests/JsonParserTests.vcxproj.filters
@@ -33,9 +33,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -45,6 +42,9 @@
Source Files
+
+ Source Files
+
Source Files