diff --git a/API-Reference.md b/API-Reference.md index b29b27a..fe5a244 100644 --- a/API-Reference.md +++ b/API-Reference.md @@ -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 (JsonObjectKey key) const; +const char* get (JsonObjectKey key) const; +double get (JsonObjectKey key) const; +float get (JsonObjectKey key) const; +signed char get (JsonObjectKey key) const; +signed int get (JsonObjectKey key) const; +signed long get (JsonObjectKey key) const; +signed short get (JsonObjectKey key) const; +String get (JsonObjectKey key) const; +unsigned char get (JsonObjectKey key) const; +unsigned int get (JsonObjectKey key) const; +unsigned long get (JsonObjectKey key) const; +unsigned short get (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("pi"); // template version of get() +const char* value2 = object.get("toto"); // returns NULL +``` + + :construction: :construction: Below this line, the writing is still in progress... :construction: - -## JsonObject - -#### JsonArray::get() -##### Description -Gets the value at the specified index. -##### Signatures -##### Arguments -##### Return value -##### Example - #### JsonArray::operator[] ##### Description ##### Signatures