Skip to content

Commit ed9d52c

Browse files
committed
Add String key option for operator[] and hasOwnProperty
1 parent 3803a08 commit ed9d52c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/JSONVar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ JSONVar JSONVar::operator[](const char* key)
246246
return JSONVar(json, _json);
247247
}
248248

249+
JSONVar JSONVar::operator[](const String& key)
250+
{
251+
return (*this)[key.c_str()];
252+
}
253+
249254
JSONVar JSONVar::operator[](int index)
250255
{
251256
if (!cJSON_IsArray(_json)) {
@@ -322,6 +327,11 @@ bool JSONVar::hasOwnProperty(const char* key) const
322327
return (json != NULL);
323328
}
324329

330+
bool JSONVar::hasOwnProperty(const String& key) const
331+
{
332+
return hasOwnProperty(key.c_str());
333+
}
334+
325335
JSONVar JSONVar::parse(const char* s)
326336
{
327337
cJSON* json = cJSON_Parse(s);

src/JSONVar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ class JSONVar : public Printable {
6767
bool operator==(nullptr_t) const;
6868

6969
JSONVar operator[](const char* key);
70+
JSONVar operator[](const String& key);
7071
JSONVar operator[](int index);
7172
JSONVar operator[](const JSONVar& key);
7273

7374
int length() const;
7475
JSONVar keys() const;
7576
bool hasOwnProperty(const char* key) const;
77+
bool hasOwnProperty(const String& key) const;
7678

7779
static JSONVar parse(const char* s);
7880
static JSONVar parse(const String& s);

0 commit comments

Comments
 (0)