Fix "no matching function" with JsonObjectConst::operator[]

Fixes #2019
This commit is contained in:
Benoit Blanchon
2024-01-03 16:30:44 +01:00
parent 9dc43d14f3
commit cc42373367
3 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,11 @@
ArduinoJson: change log ArduinoJson: change log
======================= =======================
HEAD
----
* Fix "no matching function" with `JsonObjectConst::operator[]` (issue #2019)
v7.0.0 (2024-01-03) v7.0.0 (2024-01-03)
------ ------

View File

@ -252,3 +252,11 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(false == obj["hello"]["world"].is<bool>()); REQUIRE(false == obj["hello"]["world"].is<bool>());
} }
} }
TEST_CASE("JsonObjectConst::operator[]") {
JsonDocument doc;
doc["hello"] = "world";
JsonObjectConst obj = doc.as<JsonObjectConst>();
REQUIRE(obj["hello"] == "world"); // issue #2019
}

View File

@ -101,8 +101,9 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value, FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
JsonVariantConst>::type JsonVariantConst>::type
operator[](TChar* key) const { operator[](TChar* key) const {
return JsonVariantConst( return JsonVariantConst(detail::ObjectData::getMember(
detail::ObjectData::getMember(data_, detail::adaptString(key))); data_, detail::adaptString(key), resources_),
resources_);
} }
// DEPRECATED: always returns zero // DEPRECATED: always returns zero