Closed wang-sy closed 1 year ago
While not as terse, I'll think you'll need to write that as
if (!obj.contains("not_exist_key"))
{
obj["not_exist_key"] = jsoncons::json(jsoncons::json_array_arg);
}
obj["not_exist_key"].push_back("array_item");
or (more efficiently) as
auto pair = obj.try_emplace("not_exist_key", jsoncons::json_array_arg); // inserts array if not exists
pair.first->value().push_back("array_item");
We don't support changing the json_type
as a result of calling a member function.
Problem Code
now
we got
cause when
key
not exist inparent
,evaluate_with_default
method only creates a new object.expect
The default operation object of the
push_back
method isarray
. When thekey
operated by the user does not exist, we should help user to complete the creation of thearray object
by default.expect result