mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-13 17:44:49 +02:00
Updated API Reference (markdown)
@@ -623,23 +623,87 @@ Serial.println(orig); // hello
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## JsonObject
|
||||||
|
|
||||||
|
Represents an object (ie an unordered set of name/value pairs) in a JSON object tree.
|
||||||
|
|
||||||
|
|
||||||
|
### Constructor
|
||||||
|
|
||||||
|
The constructor is private, you cannot instanciate a `JsonObject` directly, you have to use a `JsonBuffer`.
|
||||||
|
|
||||||
|
Because the memory of a `JsonObject` is located a `JsonBuffer`, you always manipulate it through reference and you cannot copy it.
|
||||||
|
|
||||||
|
##### Example
|
||||||
|
|
||||||
|
```c++
|
||||||
|
StaticJsonBuffer<200> jsonBuffer;
|
||||||
|
|
||||||
|
// create an empty object
|
||||||
|
JsonObject& object1 = jsonBuffer.createObject();
|
||||||
|
|
||||||
|
// parse a JSON object
|
||||||
|
char json[] = "[1,2,3]";
|
||||||
|
JsonObject& object2 = jsonBuffer.parseObject(json);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### JsonObject::get()
|
||||||
|
|
||||||
|
##### Description
|
||||||
|
Gets the value at the specified index.
|
||||||
|
|
||||||
|
##### Signature
|
||||||
|
```c++
|
||||||
|
// Non template version
|
||||||
|
JsonVariant get (JsonObjectKey key) const;
|
||||||
|
|
||||||
|
// Template version
|
||||||
|
bool get<bool> (JsonObjectKey key) const;
|
||||||
|
const char* get<const char*> (JsonObjectKey key) const;
|
||||||
|
double get<double> (JsonObjectKey key) const;
|
||||||
|
float get<float> (JsonObjectKey key) const;
|
||||||
|
signed char get<signed char> (JsonObjectKey key) const;
|
||||||
|
signed int get<signed int> (JsonObjectKey key) const;
|
||||||
|
signed long get<signed long> (JsonObjectKey key) const;
|
||||||
|
signed short get<signed short> (JsonObjectKey key) const;
|
||||||
|
String get<String> (JsonObjectKey key) const;
|
||||||
|
unsigned char get<unsigned char> (JsonObjectKey key) const;
|
||||||
|
unsigned int get<unsigned int> (JsonObjectKey key) const;
|
||||||
|
unsigned long get<unsigned long> (JsonObjectKey key) const;
|
||||||
|
unsigned short get<unsigned short> (JsonObjectKey key) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Arguments
|
||||||
|
|
||||||
|
`key`: the key of the the value in the object, can be a `const char*` or a `const String&`
|
||||||
|
|
||||||
|
`T`: the type of the value
|
||||||
|
|
||||||
|
##### Return value
|
||||||
|
|
||||||
|
The value at the specified key. This can be a `JsonVariant` or a value of type `T`.
|
||||||
|
|
||||||
|
The template version of `get()` returns a value of the specified type.
|
||||||
|
In case of an error (key out of range or incompatible type), the default value of the type `T` is returned.
|
||||||
|
|
||||||
|
##### Example
|
||||||
|
|
||||||
|
```c++
|
||||||
|
char json[] = "{\"pi\":3.14}";
|
||||||
|
StaticJsonBuffer<256> jsonBuffer;
|
||||||
|
JsonObject& object = jsonBuffer.parseObject(json);
|
||||||
|
float pi = object.get<float>("pi"); // template version of get()
|
||||||
|
const char* value2 = object.get<const char*>("toto"); // returns NULL
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
:construction:
|
:construction:
|
||||||
|
|
||||||
:construction: Below this line, the writing is still in progress...
|
:construction: Below this line, the writing is still in progress...
|
||||||
|
|
||||||
:construction:
|
:construction:
|
||||||
|
|
||||||
|
|
||||||
## JsonObject
|
|
||||||
|
|
||||||
#### JsonArray::get()
|
|
||||||
##### Description
|
|
||||||
Gets the value at the specified index.
|
|
||||||
##### Signatures
|
|
||||||
##### Arguments
|
|
||||||
##### Return value
|
|
||||||
##### Example
|
|
||||||
|
|
||||||
#### JsonArray::operator[]
|
#### JsonArray::operator[]
|
||||||
##### Description
|
##### Description
|
||||||
##### Signatures
|
##### Signatures
|
||||||
|
Reference in New Issue
Block a user