Răsfoiți Sursa

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

Fixes #2019
Benoit Blanchon 2 ani în urmă
părinte
comite
cc42373367

+ 5 - 0
CHANGELOG.md

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

+ 8 - 0
extras/tests/JsonObject/subscript.cpp

@@ -252,3 +252,11 @@ TEST_CASE("JsonObject::operator[]") {
     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
+}

+ 3 - 2
src/ArduinoJson/Object/JsonObjectConst.hpp

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