Compile Error using JsonVariant
Created by: tbnobody
I had the following code running on a ESP8266 using the Arduino Framework:
StaticJsonBuffer<1024> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
JsonArray& data = root[F("button")];
uint8_t cnt = 0;
for (auto dataobj : data) {
config.Button_Config[cnt].animation = dataobj[F("animation")].as<uint>();
config.Button_Config[cnt].color = StripeAnimation.ConvertStringToColor(dataobj[F("color")].as<String>());
cnt++;
if (cnt > MAX_BUTTON_CONFIG) {
break;
}
}
This code worked perfectly including commit 11432253 and does not work with commit 8499f0b9
I get the following error message:
ArduinoJson.hpp:12: In file included from
ArduinoJson.h:8: from
ArduinoJson.h:8: from
AsyncJson.h:23: from
WebAPI.h:17: from
WebAPI.cpp:8: from
JsonObject.hpp: In instantiation of typename ArduinoJson::Internals::JsonVariantAs<TValue>::type ArduinoJson::JsonObject::get_impl(TStringRef) const [with TStringRef = const __FlashStringHelper*; TValue = ArduinoJson::JsonObjectSubscript<const __FlashStringHelper* const&>; typename ArduinoJson::Internals::JsonVariantAs<TValue>::type = ArduinoJson::JsonObjectSubscript<const __FlashStringHelper* const&>]
JsonObject.hpp:179: required from typename ArduinoJson Internals JsonVariantAs<T> type ArduinoJson JsonObject get(const TString*) const [with TValue = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>; TString = __FlashStringHelper; typename ArduinoJson Internals JsonVariantAs<T> type = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>]
JsonObjectSubscript.hpp:64: required from typename ArduinoJson Internals JsonVariantAs<T> type ArduinoJson JsonObjectSubscript<TKey> as() const [with TValue = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>; TStringRef = const __FlashStringHelper*; typename ArduinoJson Internals JsonVariantAs<T> type = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>]
JsonVariantBase.hpp:63: required from const typename ArduinoJson Internals JsonVariantAs<T> type ArduinoJson JsonVariantBase<TImpl> as() const [with T = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>; TImpl = ArduinoJson JsonObjectSubscript<const __FlashStringHelper*>; typename ArduinoJson Internals JsonVariantAs<T> type = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>]
JsonVariantBase.hpp:58: required from ArduinoJson JsonVariantBase<TImpl> operator T() const [with T = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>; TImpl = ArduinoJson JsonObjectSubscript<const __FlashStringHelper*>]
JsonVariantBase.hpp:101: required from typename ArduinoJson TypeTraits EnableIf<ArduinoJson Internals StringTraits<TString> has_equals, ArduinoJson JsonObjectSubscript<const TString&> > type ArduinoJson JsonVariantBase<TImpl> operator[](const TString&) [with TString = const __FlashStringHelper*; TImpl = ArduinoJson JsonVariant; typename ArduinoJson TypeTraits EnableIf<ArduinoJson Internals StringTraits<TString> has_equals, ArduinoJson JsonObjectSubscript<const TString&> > type = ArduinoJson JsonObjectSubscript<const __FlashStringHelper* const&>]
WebAPI.cpp:942: required from here
JsonObject.hpp: 301:17: error: no matching function for call to 'ArduinoJson::JsonVariant::as()
return node ? node->content.value.as<TValue>()
JsonObject.hpp:301: note candidates are
The line 942 in WebAPI.cpp is the following line (as in the above code snippet):
config.Button_Config[cnt].animation = dataobj[F("animation")].as<uint>();
I am not very familiar with templates, but due to the fact it worked in the previous versions it's maybe not wanted to throw an error here?