mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			833 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			833 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
| * malloc-free JSON parser for Arduino
 | |
| * Benoit Blanchon 2014 - MIT License
 | |
| */
 | |
| 
 | |
| #ifndef __JSONPARSER_H
 | |
| #define __JSONPARSER_H
 | |
| 
 | |
| #include "JsonHashTable.h"
 | |
| #include "JsonArray.h"
 | |
| 
 | |
| template <int SIZE> // SIZE of the parser in bytes  (128, 256 or more are recommended)
 | |
| class JsonParser
 | |
| {
 | |
| public:
 | |
| 
 | |
| 	JsonArray parseArray(char* json)
 | |
| 	{
 | |
| 		return JsonArray(json, parse(json));
 | |
| 	}
 | |
| 
 | |
| 	JsonHashTable parseHashTable(char* json)
 | |
| 	{
 | |
| 		return JsonHashTable(json, parse(json));
 | |
| 	}
 | |
| 
 | |
| private:
 | |
| 
 | |
| 	jsmntok_t* parse(char* json)
 | |
| 	{
 | |
| 		jsmn_parser parser;
 | |
| 		jsmn_init(&parser);
 | |
| 
 | |
| 		jsmntok_t* tokens = (jsmntok_t*) buffer;
 | |
| 		int maxTokenCount = SIZE / sizeof(jsmntok_t);
 | |
| 
 | |
| 		if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokenCount))
 | |
| 			return 0;
 | |
| 
 | |
| 		return tokens;
 | |
| 	}
 | |
| 
 | |
| 	char buffer[SIZE];
 | |
| };
 | |
| 
 | |
| #endif
 | |
| 
 |