Issue with JsonVariant.as<T>() where T is char * Need to update docs!
Created by: djaus2
Describe the bug
When using the example to iterate thjrough elements of a Json Document ins the part .as<T>()
can't use char* for T
Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:
- The issue happens at compile time
- Error says "no matching function for call to
...(<unresolved overloaded function type>)
" - Adding the parentheses doesn't fix the issue .. Weren't missing in the parenthesis first place.
PS Liked that trouble shooter.
Environment
Here is the environment that I used:
- Microcontroller: RP2040
- RPI Pico W
- IDE: Arduino IDE 1.2.03
Reproduction
This is a compile time error only.
Small sketch with same code as per documentation:
DynamicJsonDocument doc(1024);
deserializeJson(doc, "{\"first\":\"\",\"second\":\"second\"}");
JsonObject root = doc.as<JsonObject>();
// using C++11 syntax (preferred):
for (JsonPair kv : root) {
Serial.println(kv.key().c_str());
Serial.println(kv.value().as<char *>());
}
Workaround: replace char * with String
Further: I see its deprecated anyway
const char* as<char*>() const; //
SO DOCUMENTATION NEEDS UPDATE.. I spent hours on this! But thanks anyway for the library.
Compiler output
Compilation error: no matching function for call to 'ArduinoJson6200_F1::JsonVariant::as<char*>()'