mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Added JsonHashTable.getArray()
This commit is contained in:
@ -34,7 +34,7 @@ bool JsonParserBase::parse(char* jsonString)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* JsonHashTable::getString(char* name)
|
jsmntok_t* JsonHashTable::getToken(char* name)
|
||||||
{
|
{
|
||||||
// skip first token, it's the whole object
|
// skip first token, it's the whole object
|
||||||
int currentToken = 1;
|
int currentToken = 1;
|
||||||
@ -48,7 +48,7 @@ char* JsonHashTable::getString(char* name)
|
|||||||
// Compare with desired name
|
// Compare with desired name
|
||||||
if (strcmp(name, key) == 0)
|
if (strcmp(name, key) == 0)
|
||||||
{
|
{
|
||||||
return json + tokens[currentToken + 1].start;
|
return &tokens[currentToken + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// move forward: key + value + nested tokens
|
// move forward: key + value + nested tokens
|
||||||
@ -58,6 +58,12 @@ char* JsonHashTable::getString(char* name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonArray JsonHashTable::getArray(char* key)
|
||||||
|
{
|
||||||
|
jsmntok_t* token = getToken(key);
|
||||||
|
return JsonArray(json, token);
|
||||||
|
}
|
||||||
|
|
||||||
char* JsonArray::getString(int index)
|
char* JsonArray::getString(int index)
|
||||||
{
|
{
|
||||||
if (json == NULL) return NULL;
|
if (json == NULL) return NULL;
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utility/jsmn.h"
|
#include "utility/jsmn.h"
|
||||||
|
|
||||||
class JsonArray;
|
|
||||||
|
|
||||||
class JsonObjectBase
|
class JsonObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -41,6 +39,8 @@ protected:
|
|||||||
jsmntok_t* tokens;
|
jsmntok_t* tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class JsonArray;
|
||||||
|
|
||||||
class JsonHashTable : public JsonObjectBase
|
class JsonHashTable : public JsonObjectBase
|
||||||
{
|
{
|
||||||
friend class JsonParserBase;
|
friend class JsonParserBase;
|
||||||
@ -52,7 +52,12 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* getString(char* key);
|
char* getString(char* key)
|
||||||
|
{
|
||||||
|
jsmntok_t* token = getToken(key);
|
||||||
|
return token != NULL ? json + token->start : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
JsonArray getArray(char* key);
|
JsonArray getArray(char* key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -62,11 +67,14 @@ private:
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsmntok_t* getToken(char* key);
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonArray : public JsonObjectBase
|
class JsonArray : public JsonObjectBase
|
||||||
{
|
{
|
||||||
friend class JsonParserBase;
|
friend class JsonParserBase;
|
||||||
|
friend class JsonHashTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user