|
@@ -75,23 +75,22 @@ Json::Json(std::nullptr_t null)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-Json::Json(double val)
|
|
|
- : node_(json_value_create(JSON_VALUE_NUMBER, val)), parent_(nullptr),
|
|
|
- allocated_(true)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-Json::Json(int val)
|
|
|
- : node_(json_value_create(JSON_VALUE_NUMBER, static_cast<double>(val))),
|
|
|
+Json::Json(bool val)
|
|
|
+ : node_(val ? json_value_create(JSON_VALUE_TRUE)
|
|
|
+ : json_value_create(JSON_VALUE_FALSE)),
|
|
|
parent_(nullptr), allocated_(true)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-Json::Json(bool val)
|
|
|
- : node_(val ? json_value_create(JSON_VALUE_TRUE)
|
|
|
- : json_value_create(JSON_VALUE_FALSE)),
|
|
|
+Json::Json(const std::vector<std::string>& val)
|
|
|
+ : node_(json_value_create(JSON_VALUE_ARRAY)),
|
|
|
parent_(nullptr), allocated_(true)
|
|
|
{
|
|
|
+ json_array_t* arr = json_value_array(node_);
|
|
|
+ for (const auto& str : val)
|
|
|
+ {
|
|
|
+ json_array_append(arr, JSON_VALUE_STRING, str.c_str());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// for parse
|
|
@@ -378,6 +377,11 @@ bool Json::can_obj_push_back()
|
|
|
|
|
|
void Json::push_back(const std::string& key, bool val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Object{{key, val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_obj_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -389,6 +393,11 @@ void Json::push_back(const std::string& key, bool val)
|
|
|
|
|
|
void Json::push_back(const std::string& key, std::nullptr_t val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Object{{key, val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_obj_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -404,6 +413,11 @@ void Json::push_back(const std::string& key, const std::string& val)
|
|
|
|
|
|
void Json::push_back(const std::string& key, const char* val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Object{{key, val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_obj_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -414,6 +428,11 @@ void Json::push_back(const std::string& key, const char* val)
|
|
|
|
|
|
void Json::push_back(const std::string& key, const std::vector<std::string>& val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Object{{key, val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_obj_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -430,6 +449,11 @@ void Json::push_back(const std::string& key, const std::vector<std::string>& val
|
|
|
|
|
|
void Json::push_back(const std::string& key, const Json& val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Object{{key, val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_obj_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -552,15 +576,18 @@ void Json::normal_push_back(const std::string& key,
|
|
|
{
|
|
|
json_object_t* obj = json_value_object(parent_);
|
|
|
const json_value_t* find = json_object_find(key.c_str(), obj);
|
|
|
+ const json_value_t* v;
|
|
|
if (find == nullptr)
|
|
|
{
|
|
|
- json_object_append(obj, key.c_str(), JSON_VALUE_NULL);
|
|
|
- return;
|
|
|
+ v = json_object_append(obj, key.c_str(), JSON_VALUE_ARRAY);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ v = json_object_insert_before(find, obj, key.c_str(),
|
|
|
+ JSON_VALUE_ARRAY);
|
|
|
+ json_value_t* remove_val = json_object_remove(find, obj);
|
|
|
+ json_value_destroy(remove_val);
|
|
|
}
|
|
|
- const json_value_t *v = json_object_insert_before(find, obj, key.c_str(),
|
|
|
- JSON_VALUE_ARRAY);
|
|
|
- json_value_t* remove_val = json_object_remove(find, obj);
|
|
|
- json_value_destroy(remove_val);
|
|
|
json_array_t* arr = json_value_array(v);
|
|
|
for (const auto& str : val)
|
|
|
json_array_append(arr, JSON_VALUE_STRING, str.c_str());
|
|
@@ -599,6 +626,11 @@ Json Json::copy() const
|
|
|
|
|
|
void Json::push_back(bool val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Array{{val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_arr_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -610,6 +642,11 @@ void Json::push_back(bool val)
|
|
|
|
|
|
void Json::push_back(std::nullptr_t val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Array{{val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_arr_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -632,6 +669,11 @@ void Json::push_back(const std::vector<std::string>& val)
|
|
|
|
|
|
void Json::push_back(const char* val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Array{{val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_arr_push_back())
|
|
|
{
|
|
|
return;
|
|
@@ -642,6 +684,11 @@ void Json::push_back(const char* val)
|
|
|
|
|
|
void Json::push_back(const Json& val)
|
|
|
{
|
|
|
+ if (is_placeholder())
|
|
|
+ {
|
|
|
+ *this = Json::Array{{val}};
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!can_arr_push_back())
|
|
|
{
|
|
|
return;
|