fix string value parameter

This commit is contained in:
gb 2022-12-31 11:50:15 +08:00
parent d464c09d2c
commit d1f0cbf5a7
2 changed files with 4 additions and 4 deletions

View File

@ -514,7 +514,7 @@ bool json::set_value(const char* key, double val)
return true; return true;
} }
bool json::set_value(const char* key, std::string val) bool json::set_value(const char* key, const char* val)
{ {
if (type_ != VAL_TYPE_OBJECT) if (type_ != VAL_TYPE_OBJECT)
return false; return false;
@ -526,12 +526,12 @@ bool json::set_value(const char* key, std::string val)
child->clear(); child->clear();
child->type_ = VAL_TYPE_STRING; child->type_ = VAL_TYPE_STRING;
child->key() = key ? key : ""; child->key() = key ? key : "";
child->strval_ = val; child->strval_ = val ? val : "";
child->release(); child->release();
} }
else else
{ {
child = new json(key, val.c_str()); child = new json(key, val);
arr_val_.push_back(child); arr_val_.push_back(child);
} }

View File

@ -111,7 +111,7 @@ public:
bool set_value(const char* key, bool val); bool set_value(const char* key, bool val);
bool set_value(const char* key, int val); bool set_value(const char* key, int val);
bool set_value(const char* key, double val); bool set_value(const char* key, double val);
bool set_value(const char* key, std::string val); bool set_value(const char* key, const char* val);
bool set_value(const char* key, json* val); bool set_value(const char* key, json* val);
// operator+= only for array // operator+= only for array