forked from bblanchon/ArduinoJson
Minor changes in the docs
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
Migrating code written for Arduino JSON v3 to v4
|
||||
================================================
|
||||
|
||||
Arduino JSON v4 was a major rewrite of the library, and the API change significantly.
|
||||
Arduino JSON v4 was a major rewrite of the library, and the API changed significantly.
|
||||
|
||||
## Includes
|
||||
|
||||
@ -14,12 +14,6 @@ Arduino JSON v4 only has one:
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
Node: the header `src/ArduinoJson.h` is intended to be used within the Arduino IDE, if you're in another environment, you may need to include the following headers:
|
||||
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
|
||||
## Namespaces
|
||||
|
||||
Arduino JSON v3 had two namespaces:
|
||||
@ -27,15 +21,12 @@ Arduino JSON v3 had two namespaces:
|
||||
using namespace ArduinoJson::Parser;
|
||||
using namespace ArduinoJson::Generator;
|
||||
|
||||
Arduino JSON v4 only has one:
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
If you include the header `ArduinoJson.h` (recommended if in Arduino IDE), the `using` directivei is already done for you, so you don't have to write it.
|
||||
Arduino JSON v4 doesn't require the `using namespace` statement.
|
||||
It has a namespace but the `using namespace` is done in the header file.
|
||||
|
||||
## StaticJsonBuffer
|
||||
|
||||
Arduino JSON v3 had different memory allocation models for parser:
|
||||
Arduino JSON v3 had different memory allocation models for the parser:
|
||||
|
||||
JsonParser<16> parser; // 16 being the capacity in "tokens"
|
||||
|
||||
@ -44,18 +35,18 @@ and for the generator:
|
||||
JsonArray<4> array; // 4 being the number of element
|
||||
JsonObject<4> object;
|
||||
|
||||
Arduino JSON v4 only has one memory allocation mode:
|
||||
Arduino JSON v4 only has one memory allocation model:
|
||||
|
||||
StaticJsonBuffer<128> buffer; // 128 being the capacity in bytes
|
||||
|
||||
## Return values for the parser
|
||||
|
||||
Arduino JSON v3 returned `JsonArray` and `JsonObject`:
|
||||
Arduino JSON v3 returned value types:
|
||||
|
||||
JsonArray array = parser.parseArray(json);
|
||||
JsonObject object = parser.parseObject(json);
|
||||
|
||||
Arduino JSON v4 returns references:
|
||||
Arduino JSON v4 returns references types:
|
||||
|
||||
JsonArray& array = buffer.parseArray(json);
|
||||
JsonObject& object = buffer.parseObject(json);
|
||||
@ -78,11 +69,11 @@ Note: you don't have to specify the capacity anymore.
|
||||
|
||||
## Printable interface
|
||||
|
||||
Arduino JSON v3 used to implement the Printable interface, that allowed that kind of statement:
|
||||
Arduino JSON v3 used to implement the Printable interface, which allowed statements like:
|
||||
|
||||
Serial.print(array);
|
||||
|
||||
Arduino JSON v4 doesn't, so you need to write this:
|
||||
But Arduino JSON v4 doesn't, instead you need to write this:
|
||||
|
||||
array.printTo(Serial);
|
||||
|
||||
|
Reference in New Issue
Block a user