mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added namespace for the parser
This commit is contained in:
		| @@ -6,6 +6,8 @@ | ||||
| #include "JsonArray.h" | ||||
| #include "JsonHashTable.h" | ||||
|  | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| JsonArray::JsonArray(char* json, jsmntok_t* tokens) | ||||
| : JsonObjectBase(json, tokens) | ||||
| { | ||||
|   | ||||
| @@ -7,16 +7,20 @@ | ||||
|  | ||||
| #include "JsonObjectBase.h" | ||||
|  | ||||
| class JsonHashTable; | ||||
|  | ||||
| class JsonArray : public JsonObjectBase | ||||
| namespace ArduinoJson | ||||
| { | ||||
|     namespace Parser | ||||
|     { | ||||
|         class JsonHashTable; | ||||
|  | ||||
|         class JsonArray : public JsonObjectBase | ||||
|         { | ||||
|             template <int N> | ||||
|             friend class JsonParser; | ||||
|  | ||||
|             friend class JsonHashTable; | ||||
|  | ||||
| public: | ||||
|         public: | ||||
|  | ||||
|             JsonArray()	{} | ||||
|  | ||||
| @@ -32,8 +36,10 @@ public: | ||||
|             long getLong(int index); | ||||
|             char* getString(int index); | ||||
|  | ||||
| private: | ||||
|         private: | ||||
|  | ||||
|             JsonArray(char* json, jsmntok_t* tokens); | ||||
|             jsmntok_t* getToken(int index); | ||||
| }; | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @@ -3,10 +3,11 @@ | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
|  | ||||
| #include <string.h> // for strcmp() | ||||
| #include "JsonArray.h" | ||||
| #include "JsonHashTable.h" | ||||
|  | ||||
| #include <string.h> // for strcmp() | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| JsonHashTable::JsonHashTable(char* json, jsmntok_t* tokens) | ||||
| : JsonObjectBase(json, tokens) | ||||
|   | ||||
| @@ -7,16 +7,20 @@ | ||||
|  | ||||
| #include "JsonObjectBase.h" | ||||
|  | ||||
| class JsonArray; | ||||
|  | ||||
| class JsonHashTable : public JsonObjectBase | ||||
| namespace ArduinoJson | ||||
| { | ||||
|     namespace Parser | ||||
|     { | ||||
|         class JsonArray; | ||||
|  | ||||
|         class JsonHashTable : public JsonObjectBase | ||||
|         { | ||||
|             template <int N> | ||||
|             friend class JsonParser; | ||||
|  | ||||
|             friend class JsonArray; | ||||
|  | ||||
| public: | ||||
|         public: | ||||
|  | ||||
|             JsonHashTable() {} | ||||
|  | ||||
| @@ -29,8 +33,10 @@ public: | ||||
|             long getLong(const char* key); | ||||
|             char* getString(const char* key); | ||||
|  | ||||
| private: | ||||
|         private: | ||||
|  | ||||
|             JsonHashTable(char* json, jsmntok_t* tokens); | ||||
|             jsmntok_t* getToken(const char* key); | ||||
| }; | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @@ -3,9 +3,10 @@ | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
|  | ||||
| #include <stdlib.h> // for strtol, strtod | ||||
| #include "JsonObjectBase.h" | ||||
|  | ||||
| #include <stdlib.h> // for strtol, strtod | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| int JsonObjectBase::getNestedTokenCount(jsmntok_t* token) | ||||
| { | ||||
|   | ||||
| @@ -7,9 +7,13 @@ | ||||
|  | ||||
| #include "jsmn.h" | ||||
|  | ||||
| class JsonObjectBase | ||||
| namespace ArduinoJson | ||||
| { | ||||
| public: | ||||
|     namespace Parser | ||||
|     { | ||||
|         class JsonObjectBase | ||||
|         { | ||||
|         public: | ||||
|  | ||||
|             JsonObjectBase() | ||||
|             { | ||||
| @@ -21,7 +25,7 @@ public: | ||||
|                 return json != 0 && tokens != 0; | ||||
|             } | ||||
|  | ||||
| protected: | ||||
|         protected: | ||||
|  | ||||
|             JsonObjectBase(char* json, jsmntok_t* tokens) | ||||
|             { | ||||
| @@ -44,4 +48,6 @@ protected: | ||||
|  | ||||
|             char* json; | ||||
|             jsmntok_t* tokens; | ||||
| }; | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @@ -8,23 +8,27 @@ | ||||
| #include "JsonHashTable.h" | ||||
| #include "JsonArray.h" | ||||
|  | ||||
| /* | ||||
| * The JSON parser. | ||||
| * | ||||
| * You need to specifiy the number of token to be allocated for that parser. | ||||
| * Values from 16 to 32 are recommended. | ||||
| * The parser size will be MAX_TOKEN*8 bytes. | ||||
| * Don't forget that the memory size of standard Arduino board is only 2KB | ||||
| * | ||||
| * CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the | ||||
| * JsonParser, so they need the JsonParser to be in memory to work. | ||||
| * As a result, you must not create JsonArray and JsonHashTable that have a  | ||||
| * longer life that the JsonParser. | ||||
| */ | ||||
| template <int MAX_TOKENS> | ||||
| class JsonParser | ||||
| namespace ArduinoJson | ||||
| { | ||||
| public: | ||||
|     namespace Parser | ||||
|     { | ||||
|         /* | ||||
|         * The JSON parser. | ||||
|         * | ||||
|         * You need to specifiy the number of token to be allocated for that parser. | ||||
|         * Values from 16 to 32 are recommended. | ||||
|         * The parser size will be MAX_TOKEN*8 bytes. | ||||
|         * Don't forget that the memory size of standard Arduino board is only 2KB | ||||
|         * | ||||
|         * CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the | ||||
|         * JsonParser, so they need the JsonParser to be in memory to work. | ||||
|         * As a result, you must not create JsonArray and JsonHashTable that have a | ||||
|         * longer life that the JsonParser. | ||||
|         */ | ||||
|         template <int MAX_TOKENS> | ||||
|         class JsonParser | ||||
|         { | ||||
|         public: | ||||
|  | ||||
|             /* | ||||
|             * Parse the JSON string and return a array. | ||||
| @@ -48,7 +52,7 @@ public: | ||||
|                 return JsonHashTable(json, parse(json)); | ||||
|             } | ||||
|  | ||||
| private: | ||||
|         private: | ||||
|  | ||||
|             jsmntok_t* parse(char* json) | ||||
|             { | ||||
| @@ -62,4 +66,6 @@ private: | ||||
|             } | ||||
|  | ||||
|             jsmntok_t tokens[MAX_TOKENS]; | ||||
| }; | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @@ -7,6 +7,7 @@ | ||||
| #include "JsonParser.h" | ||||
|  | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| #include "JsonParser.h" | ||||
|  | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
|  | ||||
| using namespace std; | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
|  | ||||
| using namespace std; | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| {		 | ||||
|   | ||||
| @@ -5,6 +5,8 @@ | ||||
|  | ||||
| #include <JsonParser.h> | ||||
|  | ||||
| using namespace ArduinoJson::Parser; | ||||
|  | ||||
| void ParseAnObject() | ||||
| { | ||||
|     char json[] = "{\"Name\":\"Blanchon\",\"Skills\":[\"C\",\"C++\",\"C#\"],\"Age\":32,\"Online\":true}"; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user