Add object as String with 'firstString + secondString' fails
Created by: beegee-tokyo
IDE: Arduino IDE IDE version 1.6.6 Target: ESP8266 ArduinoJson version 5.0.7
First: Thanks a lot for this awesome library!!!! It is a great help to decode and encode JSON objects and arrays!
Second: Problem I am trying to generate a json object with an entry called "result". The content of "result" would be a keyword (firstString) and a description (secondString).
When I try:
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
...
String req = httpClient.readStringUntil('\r');
...
root["result"] = "fail " + req;
I get a long error list in Arduino IDE
In file included from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObject.ipp:10:0,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObject.hpp:151,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson.h:9,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/ArduinoJson.h:13,
from D:\ESP8266\Projects\IR-FujiDenzo\IR-FujiDenzo.ino:23:
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObjectSubscript.hpp: In instantiation of 'ArduinoJson::JsonObjectSubscript<TKey>& ArduinoJson::JsonObjectSubscript<TKey>::operator=(const T&) [with T = StringSumHelper; TKey = const char*]':
D:\ESP8266\Projects\IR-FujiDenzo\IR-FujiDenzo_1_Subs.ino:253:18: required from here
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObjectSubscript.hpp:35:25: error: no matching function for call to 'ArduinoJson::JsonObjectSubscript<const char*>::assign(const StringSumHelper&)'
JsonVariant>(src);
^
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObjectSubscript.hpp:35:25: note: candidate is:
In file included from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonArraySubscript.hpp:9:0,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonArray.ipp:10,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonArray.hpp:135,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson.h:8,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/ArduinoJson.h:13,
from D:\ESP8266\Projects\IR-FujiDenzo\IR-FujiDenzo.ino:23:
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonSubscriptBase.hpp:76:23: note: template<class TValue> TImpl& ArduinoJson::JsonSubscriptBase<TImpl>::assign(TValue) [with TValue = TValue; TImpl = ArduinoJson::JsonObjectSubscript<const char*>]
FORCE_INLINE TImpl& assign(TValue value) {
^
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonSubscriptBase.hpp:76:23: note: template argument deduction/substitution failed:
In file included from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObject.ipp:10:0,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObject.hpp:151,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson.h:9,
from D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/ArduinoJson.h:13,
from D:\ESP8266\Projects\IR-FujiDenzo\IR-FujiDenzo.ino:23:
D:\Arduino-Dev\Projects\libraries\ArduinoJson\src/../include/ArduinoJson/JsonObjectSubscript.hpp:35:25: note: cannot convert 'src' (type 'const StringSumHelper') to type 'ArduinoJson::JsonVariant'
JsonVariant>(src);
^
exit status 1
Error compiling.
If I use
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
...
String req = httpClient.readStringUntil('\r');
...
String statResponse = "fail " + req;
root["result"] = statResponse;
it works fine.
Any possibility to implement 'String Addition Operator' functionality? I am running out of memory in my project and would not like to add another String variable. If it adds too much overhead on the library, I understand and will stick with a String variable to create the JSON entry.