mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 21:12:25 +02:00
Added JsonObjectIterator
This commit is contained in:
@ -22,10 +22,9 @@ namespace ArduinoJson
|
||||
|
||||
}
|
||||
|
||||
const JsonArrayIterator& operator++()
|
||||
void operator++()
|
||||
{
|
||||
token = token.nextSibling();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonValue operator*() const
|
||||
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "JsonValue.h"
|
||||
#include "JsonObjectIterator.h"
|
||||
|
||||
namespace ArduinoJson
|
||||
{
|
||||
@ -43,6 +44,16 @@ namespace ArduinoJson
|
||||
return getValue(key).success();
|
||||
}
|
||||
|
||||
JsonObjectIterator begin()
|
||||
{
|
||||
return JsonObjectIterator(json, token.firstChild());
|
||||
}
|
||||
|
||||
JsonObjectIterator end()
|
||||
{
|
||||
return JsonObjectIterator(json, token.nextSibling());
|
||||
}
|
||||
|
||||
DEPRECATED JsonArray getArray(const char* key);
|
||||
|
||||
DEPRECATED bool getBool(const char* key)
|
||||
|
47
JsonParser/JsonObjectIterator.h
Normal file
47
JsonParser/JsonObjectIterator.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonValue.h"
|
||||
#include "JsonPair.h"
|
||||
#include "JsonToken.h"
|
||||
|
||||
namespace ArduinoJson
|
||||
{
|
||||
namespace Parser
|
||||
{
|
||||
class JsonObjectIterator
|
||||
{
|
||||
public:
|
||||
|
||||
JsonObjectIterator(char* json, Internal::JsonToken token)
|
||||
: json(json), token(token)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
token = token.nextSibling().nextSibling();
|
||||
}
|
||||
|
||||
JsonPair operator*() const
|
||||
{
|
||||
return JsonPair(json, token);
|
||||
}
|
||||
|
||||
bool operator !=(const JsonObjectIterator& other)
|
||||
{
|
||||
return token != other.token;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char* json;
|
||||
Internal::JsonToken token;
|
||||
};
|
||||
}
|
||||
}
|
39
JsonParser/JsonPair.h
Normal file
39
JsonParser/JsonPair.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonValue.h"
|
||||
|
||||
namespace ArduinoJson
|
||||
{
|
||||
namespace Parser
|
||||
{
|
||||
class JsonPair
|
||||
{
|
||||
public:
|
||||
|
||||
JsonPair(char* json, Internal::JsonToken token)
|
||||
: json(json), token(token)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const char* key()
|
||||
{
|
||||
return token.getText(json);
|
||||
}
|
||||
|
||||
JsonValue value()
|
||||
{
|
||||
return JsonValue(json, token.nextSibling());
|
||||
}
|
||||
|
||||
private:
|
||||
char* json;
|
||||
Internal::JsonToken token;
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user