How to use the String
class on Particle?
If you try to use the String
class with ArduinoJson on a Particle device (Argon, Boron, Electron, Photon, Xenon…), you’ll probably get a compilation error like:
call of overloaded 'set(const String&)' is ambiguous
no type named 'Reader' in 'struct ArduinoJson::Internals::StringTraits<String, void>'
no matching function for call to 'serialize(const ArduinoJson6112_11000::BasicJsonDocument<ArduinoJson6112_11000::DefaultAllocator>&, String&)'
These errors occur because the support of the String
class is disabled in ArduinoJson.
ArduinoJson enables the support of the String
class when the ARDUINO
symbol is defined. Particle doesn’t define ARDUINO
unless you include Arduino.h
in your project.
To solve this problem, simply include Arduino.h
:
#include <Arduino.h>
#include <ArduinoJson.h>
Alternatively, you can force the support of the String
class by defining ARDUINOJSON_ENABLE_ARDUINO_STRING
:
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#include <ArduinoJson.h>