mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 19:42:12 +02:00
Splitted in several files
This commit is contained in:
70
JsonParser.h
Normal file
70
JsonParser.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* malloc-free JSON parser for Arduino
|
||||
* Benoit Blanchon 2014
|
||||
* MIT License
|
||||
*/
|
||||
|
||||
#ifndef __JSONPARSER_H
|
||||
#define __JSONPARSER_H
|
||||
|
||||
#include "JsonHashTable.h"
|
||||
#include "JsonArray.h"
|
||||
|
||||
class JsonParserBase
|
||||
{
|
||||
public:
|
||||
|
||||
JsonArray parseArray(char* json)
|
||||
{
|
||||
if (!parse(json) || tokens[0].type != JSMN_ARRAY)
|
||||
return JsonArray();
|
||||
|
||||
return JsonArray(json, tokens);
|
||||
}
|
||||
|
||||
JsonHashTable parseHashTable(char* json)
|
||||
{
|
||||
if (!parse(json) || tokens[0].type != JSMN_OBJECT)
|
||||
return JsonHashTable();
|
||||
|
||||
return JsonHashTable(json, tokens);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
JsonParserBase(jsmntok_t* tokens, int maxTokenCount)
|
||||
{
|
||||
this->maxTokenCount = maxTokenCount;
|
||||
this->tokens = tokens;
|
||||
|
||||
jsmn_init(&parser);
|
||||
}
|
||||
|
||||
bool parse(char* json);
|
||||
|
||||
private:
|
||||
|
||||
char* buffer;
|
||||
jsmn_parser parser;
|
||||
int maxTokenCount;
|
||||
jsmntok_t* tokens;
|
||||
};
|
||||
|
||||
template <int N>
|
||||
class JsonParser : public JsonParserBase
|
||||
{
|
||||
public:
|
||||
|
||||
JsonParser()
|
||||
: JsonParserBase(tokens, N)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
jsmntok_t tokens[N];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user