mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
Extracted class JsonValue
This commit is contained in:
67
JsonGeneratorTests/JsonValue.h
Normal file
67
JsonGeneratorTests/JsonValue.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StringBuilder.h"
|
||||
|
||||
class JsonObjectBase;
|
||||
|
||||
class JsonValue
|
||||
{
|
||||
public:
|
||||
|
||||
JsonValue()
|
||||
{
|
||||
}
|
||||
|
||||
JsonValue(const char* value)
|
||||
: type(JSON_STRING)
|
||||
{
|
||||
content.string = value;
|
||||
}
|
||||
|
||||
JsonValue(double value)
|
||||
: type(JSON_NUMBER)
|
||||
{
|
||||
content.number = value;
|
||||
}
|
||||
|
||||
JsonValue(bool value)
|
||||
: type(JSON_BOOLEAN)
|
||||
{
|
||||
content.boolean = value;
|
||||
}
|
||||
|
||||
JsonValue(JsonObjectBase& value)
|
||||
: type(JSON_OBJECT)
|
||||
{
|
||||
content.object = &value;
|
||||
}
|
||||
|
||||
void writeTo(StringBuilder& sb);
|
||||
|
||||
private:
|
||||
|
||||
enum Type
|
||||
{
|
||||
JSON_STRING,
|
||||
JSON_NUMBER,
|
||||
JSON_BOOLEAN,
|
||||
JSON_OBJECT,
|
||||
};
|
||||
|
||||
union Content
|
||||
{
|
||||
const char* string;
|
||||
double number;
|
||||
bool boolean;
|
||||
JsonObjectBase* object;
|
||||
};
|
||||
|
||||
Type type;
|
||||
Content content;
|
||||
};
|
||||
|
Reference in New Issue
Block a user