Added verification of the type of token

This commit is contained in:
Benoit Blanchon
2014-01-11 16:41:18 +01:00
parent da37162a94
commit 4713e90f12
7 changed files with 74 additions and 74 deletions

View File

@ -1,23 +1,28 @@
/*
* malloc-free JSON parser for Arduino
* Benoit Blanchon 2014
* MIT License
*/
* malloc-free JSON parser for Arduino
* Benoit Blanchon 2014 - MIT License
*/
#include "JsonParser.h"
bool JsonParserBase::parse(char* jsonString)
JsonParserBase::JsonParserBase(jsmntok_t* tokens, int maxTokenCount)
{
buffer = jsonString;
this->maxTokenCount = maxTokenCount;
this->tokens = tokens;
jsmn_init(&parser);
}
jsmntok_t* JsonParserBase::parse(char* jsonString)
{
if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, maxTokenCount))
return false;
return 0;
// Add null termination to each token
for (int i = 1; i < parser.toknext; i++)
{
buffer[tokens[i].end] = 0;
jsonString[tokens[i].end] = 0;
}
return true;
return tokens;
}