Splitted in several files

This commit is contained in:
Benoit Blanchon
2014-01-11 15:05:35 +01:00
parent 583589c05c
commit e924bef409
10 changed files with 325 additions and 259 deletions

45
JsonHashTable.cpp Normal file
View File

@ -0,0 +1,45 @@
/*
* malloc-free JSON parser for Arduino
* Benoit Blanchon 2014
* MIT License
*/
#include "JsonArray.h"
#include "JsonHashTable.h"
#include <string.h> // for strcmp()
jsmntok_t* JsonHashTable::getToken(char* name)
{
// sanity check
if (json == 0 || tokens == 0 || name == 0)
return 0;
// skip first token, it's the whole object
int currentToken = 1;
// scan each keys
for (int i = 0; i < tokens[0].size / 2 ; i++)
{
// Get key token string
char* key = json + tokens[currentToken].start;
// Compare with desired name
if (strcmp(name, key) == 0)
{
return &tokens[currentToken + 1];
}
// move forward: key + value + nested tokens
currentToken += 2 + getNestedTokenCounts(currentToken + 1);
}
// nothing found, return NULL
return 0;
}
JsonArray JsonHashTable::getArray(char* key)
{
jsmntok_t* token = getToken(key);
return JsonArray(json, token);
}