mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 04:22:18 +02:00
Added JsonArrayParser
This commit is contained in:
@ -6,15 +6,18 @@
|
||||
|
||||
#include "ArduinoJsonParser.h"
|
||||
|
||||
bool JsonParserBase::parseTokens(char* jsonString)
|
||||
bool JsonParserBase::parseAndCheckType(char* jsonString, jsmntype_t type)
|
||||
{
|
||||
buffer = jsonString;
|
||||
|
||||
if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, tokenCount))
|
||||
if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, maxTokenCount))
|
||||
return false;
|
||||
|
||||
if (tokens[0].type != type)
|
||||
return false;
|
||||
|
||||
// Add null termination to each token
|
||||
for (int i = 0; i < tokenCount; i++)
|
||||
for (int i = 0; i < maxTokenCount; i++)
|
||||
{
|
||||
buffer[tokens[i].end] = 0;
|
||||
}
|
||||
@ -26,7 +29,7 @@ char* JsonParserBase::getValueByKey(char* name)
|
||||
{
|
||||
// Scan each keys, every two other token
|
||||
// (skip index 0, because it's the whole json object)
|
||||
for (int i = 1; i < tokenCount; i += 2)
|
||||
for (int i = 1; i < maxTokenCount; i += 2)
|
||||
{
|
||||
// Early break if we reach the last token
|
||||
if (i >= parser.toknext) break;
|
||||
@ -42,3 +45,10 @@ char* JsonParserBase::getValueByKey(char* name)
|
||||
}
|
||||
}
|
||||
|
||||
char* JsonParserBase::getValueByIndex(int index)
|
||||
{
|
||||
if (index < 0 || index >= parser.toknext)
|
||||
return NULL;
|
||||
|
||||
return buffer + tokens[index + 1].start;
|
||||
}
|
||||
|
Reference in New Issue
Block a user