diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h index 22e19391f544598bf80b62a6ef8f928439a387db..745718c1d6092a0158207cded3210f588212e29e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h @@ -18,7 +18,8 @@ #include #include -#include "cjson_object.h" +#include +#include "json_object.h" namespace DocumentDB { class JsonCommon @@ -27,11 +28,14 @@ public: JsonCommon() = default; ~JsonCommon(); - ResultValue* GetValue(CjsonObject *root, std::vector path); - static int GetIdValue(CjsonObject *root, std::vector &id); - static bool CheckIsJson(const std::string &data); - static int GetJsonDeep(const std::string &data); + static ResultValue GetValueByFiled(JsonObject *node, const std::string& filed); + static bool CheckJsonField(const std::string &data); + static int ParseNode(JsonObject *Node, std::vector singlePath, std::vector> &resultPath, bool isFirstFloor); + static std::vector> ParsePath(JsonObject* node); + static std::vector GetLeafValue(JsonObject *node); +private: + static bool CheckNode(JsonObject *Node, std::set filedSet, bool &errFlag); + static int CheckLeafNode(JsonObject *Node, std::vector &leafValue); }; - } // DocumentDB #endif // JSON_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp index 49bccc16501156ef3f1b3724b2e1e767ae617485..a87c05707d07646fc9d19500adf5d09375a17d40 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp @@ -20,51 +20,140 @@ #include "securec.h" namespace DocumentDB { -ResultValue* JsonCommon::GetValue(CjsonObject *root, std::vector path) +ResultValue JsonCommon::GetValueByFiled(JsonObject *node, const std::string& filed) { - return nullptr; + if (node == nullptr) { + return ResultValue(); + } + while (node != nullptr) { + if (node->GetItemFiled() == filed) + { + auto itemValue = node->GetItemValue(); + return itemValue; + } + if (node->GetNext().IsNull() == true) { + return ResultValue(); + } + auto nodeNew = node->GetNext(); + node = &nodeNew; + } + return ResultValue(); +} + +int JsonCommon::CheckLeafNode(JsonObject *node, std::vector &leafValue) +{ + if (node->GetChild().IsNull() == true) { + auto itemValue = node->GetItemValue(); + leafValue.emplace_back(itemValue); + } + if (node->GetChild().IsNull() != true) { + auto nodeNew = node->GetChild(); + CheckLeafNode(&nodeNew, leafValue); + } + if (node->GetNext().IsNull() != true) { + auto nodeNew = node->GetNext(); + CheckLeafNode(&nodeNew, leafValue); + } + return E_OK; } -int JsonCommon::GetIdValue(CjsonObject *root, std::vector &id) +std::vector JsonCommon::GetLeafValue(JsonObject *node) { - auto &node = root; - if (root == nullptr) { - return E_OK; + std::vector leafValue; + CheckLeafNode(node, leafValue); + return leafValue; +} + +bool JsonCommon::CheckNode(JsonObject *node, std::set filedSet, bool &errFlag) { + if (errFlag == false) { + return false; } - while (node->GetNext() != nullptr) { - if (node->GetItemFiled() == "_id") { - auto item_value = node->GetItemValue(); - if (item_value->value_type != ResultValue::ValueType::VALUE_STRING) { - return E_ERROR; - } - id.emplace_back(item_value->value_string); + std::string fieldName; + if (node->GetItemValue().valueType != ResultValue::ValueType::VALUE_NULL) { + fieldName = node->GetItemFiled(); + if (filedSet.find(fieldName) == filedSet.end()) { + filedSet.insert(fieldName); + } + else { + errFlag = false; + return false; } - node = node->GetNext(); + for (int i = 0; i < fieldName.size(); i++) { + if (!(('a'<=fieldName[i] && fieldName[i]<='z')|| ('A'<=fieldName[i] && fieldName[i]<='Z') || ('0'<=fieldName[i] && fieldName[i]<='9') || '_' == fieldName[i])) { + errFlag = false; + return false; + } + } } - return E_OK; + if (node->GetChild().IsNull() != true) { + auto nodeNew = node->GetChild(); + std::set newFiledSet; + CheckNode(&nodeNew, newFiledSet, errFlag); + } + if (node->GetNext().IsNull() != true) { + auto nodeNew = node->GetNext(); + CheckNode(&nodeNew, filedSet, errFlag); + } + return errFlag; } -bool JsonCommon::CheckIsJson(const std::string &data) { - CjsonObject cjsonObj; - if (cjsonObj.Parse(data) == E_ERROR) { +bool JsonCommon::CheckJsonField(const std::string &data) { + JsonObject jsonObj; + if (jsonObj.Init(data) != E_OK) { return false; } - return true; + std::set filedSet; + bool errFlag = true; + return CheckNode(&jsonObj, filedSet, errFlag); } -int JsonCommon::GetJsonDeep(const std::string &data) { - int lens = 0; - int deep = 0; - for (int i = 0; i < data.size(); i++) { - if (data[i] == '[' || data[i] == '{') { - lens++; - } - else if (data[i] == ']' || data[i] == '}') { - deep = std::max(deep, lens); - lens--; +int JsonCommon::ParseNode(JsonObject* node, std::vector singlePath, std::vector> &resultPath, bool isFirstFloor) +{ + std::vector fatherPath; + if (isFirstFloor) { + std::string tempParseName; + std::vector allFiledsName; + std::string priFieldName = node->GetItemFiled(); + for (int j = 0; j < priFieldName.size(); j++) { + if (priFieldName[j] != '.') { + tempParseName = tempParseName + priFieldName[j]; + } + if (priFieldName[j] == '.' || j == priFieldName.size() - 1) { + allFiledsName.emplace_back(tempParseName); + tempParseName.clear(); + } } + fatherPath = singlePath; + singlePath.insert(singlePath.end(), allFiledsName.begin(), allFiledsName.end()); + } else { + std::vector allFiledsName; + allFiledsName.emplace_back(node->GetItemFiled()); + fatherPath = singlePath; + singlePath.insert(singlePath.end(), allFiledsName.begin(), allFiledsName.end()); } - return deep; + if (node->GetChild().IsNull() != true && node->GetChild().GetItemFiled() != "") { + auto nodeNew = node->GetChild(); + ParseNode(&nodeNew, singlePath, resultPath, false); + } + else { + resultPath.emplace_back(singlePath); + } + if (node->GetNext().IsNull() != true) { + auto nodeNew = node->GetNext(); + ParseNode(&nodeNew, fatherPath, resultPath, isFirstFloor); + } + return 0; } +std::vector> JsonCommon::ParsePath(JsonObject* root) +{ + std::vector> resultPath; + auto projectionJson = root->GetChild(); + if (projectionJson.IsNull() == true) { + GLOGE("projectionJson is null"); + } + std::vector singlePath; + ParseNode(&projectionJson, singlePath, resultPath, true); + return resultPath; +} } // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h index f0ebd8fdef639a5ed7c6f73d7ffc7e14e45283a6..9b1c4119c23f7c34a4bb6b560e720a6748a19244 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h @@ -17,12 +17,22 @@ #define JSON_OBJECT_H #include +#include +#include -namespace DocumentDB { +#include "cJSON.h" +namespace DocumentDB { class JsonObject; class ResultValue { public: + ResultValue() {}; + ResultValue(const ResultValue& newValue) { + valueNumber = newValue.valueNumber; + valueString = newValue.valueString; + valueType = newValue.valueType; + valueObject = newValue.valueObject; + } enum class ValueType { VALUE_FALSE, VALUE_TRUE, @@ -32,25 +42,35 @@ public: VALUE_ARRAY, VALUE_OBJECT }; - int value_number; - std::string value_string; - ValueType value_type = ValueType::VALUE_NULL; - JsonObject *value_Object = nullptr; + int valueNumber; + std::string valueString; + ValueType valueType = ValueType::VALUE_NULL; + JsonObject *valueObject = nullptr; }; class JsonObject { public: - JsonObject () = default; - virtual ~JsonObject () = default; + JsonObject(); + JsonObject(const JsonObject& newObj); + ~JsonObject (); - virtual int Parse(const std::string &str) = 0; - virtual std::string Print() = 0; - virtual JsonObject* GetObjectItem(const std::string &field) = 0; - virtual JsonObject* GetArrayItem(const int index) = 0; - virtual ResultValue* GetItemValue() = 0; - virtual std::string GetItemFiled() = 0; - virtual int DeleteItemFromObject(const std::string &field) = 0; - virtual int Delete() = 0; + int Init(const std::string &str); + std::string Print(); + JsonObject GetObjectItem(const std::string &field, bool caseSensitive); + JsonObject GetArrayItem(const int index); + JsonObject GetNext(); + JsonObject GetChild(); + int DeleteItemFromObject(const std::string &field); + ResultValue GetItemValue(); + std::string GetItemFiled(); + JsonObject FindItem(const std::vector jsonPath); + int DeleteItemOnTarget(std::vector &path); + bool IsNull(); +private: + int GetDeep(cJSON *cjson, int deep, int &maxDeep); + cJSON *cjson_; + bool isClone_ = false; }; } // DocumentDB -#endif // JSON_OBJECT_H \ No newline at end of file +#endif // JSON_OBJECT_H + diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.cpp deleted file mode 100644 index 05eb385b1be8b0e66895ce89fff60845620863a6..0000000000000000000000000000000000000000 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "doc_errno.h" -#include "cjson_object.h" -#include "log_print.h" - -namespace DocumentDB { - -int CjsonObject::Parse(const std::string &str) -{ - cjson_ = cJSON_Parse(str.c_str()); - if (cjson_ == nullptr) { - return E_ERROR; - } - return E_OK; -} - -std::string CjsonObject::Print() -{ - if (cjson_ == nullptr) { - GLOGE("======================>NULL"); - return ""; - } - char *ret = cJSON_Print(cjson_); - std::string str = ret; - free(ret); - GLOGE("======================>%s", str.c_str()); - return str; -} - -CjsonObject* CjsonObject::GetObjectItem(const std::string &field) -{ - if (cjson_ == nullptr) { - return nullptr; - } - CjsonObject *item = new CjsonObject(); - auto cjson_item = cJSON_GetObjectItem(cjson_, field.c_str()); - if (cjson_item == nullptr) { - return item; - } - item->cjson_ = cjson_item; - return item; -} - -CjsonObject* CjsonObject::GetArrayItem(const int index) -{ - if (cjson_ == nullptr) { - return nullptr; - } - CjsonObject *item = new CjsonObject(); - auto cjson_item = cJSON_GetArrayItem(cjson_, index); - if (cjson_item == nullptr) { - return item; - } - item->cjson_ = cjson_item; - return item; -} - -CjsonObject* CjsonObject::GetNext() -{ - if (cjson_ == nullptr) { - return nullptr; - } - CjsonObject *next = new CjsonObject(); - if (cjson_->next == nullptr) { - return next; - } - next->cjson_ = cjson_->next; - return next; -} - -CjsonObject* CjsonObject::GetChild() -{ - if (cjson_ == nullptr) { - return nullptr; - } - CjsonObject *child = new CjsonObject(); - if (cjson_->child == nullptr) { - return child; - } - child->cjson_ = cjson_->child; - return child; -} - -int CjsonObject::DeleteItemFromObject(const std::string &field) -{ - if (field == "") { - return E_OK; - } - cJSON_DeleteItemFromObject(cjson_, field.c_str()); - return E_OK; -} - -ResultValue* CjsonObject::GetItemValue() -{ - if (cjson_ == nullptr) { - return nullptr; - } - ResultValue* value = new ResultValue(); - switch (cjson_->type) - { - case cJSON_False: - { - value->value_type = ResultValue::ValueType::VALUE_FALSE; - } - break; - case cJSON_True: - { - value->value_type = ResultValue::ValueType::VALUE_TRUE; - } - break; - case cJSON_NULL: - { - value->value_type = ResultValue::ValueType::VALUE_NULL; - } - break; - case cJSON_Number: - { - value->value_type = ResultValue::ValueType::VALUE_NUMBER; - value->value_number = cjson_->valuedouble; - } - break; - case cJSON_String: - { - value->value_type = ResultValue::ValueType::VALUE_STRING; - value->value_string = cjson_->valuestring; - } - break; - case cJSON_Array: - { - value->value_type = ResultValue::ValueType::VALUE_ARRAY; - value->value_Object = GetChild(); - } - break; - case cJSON_Object: - { - value->value_type = ResultValue::ValueType::VALUE_OBJECT; - value->value_Object = GetChild(); - } - break; - default: - break; - } - return value; -} - -std::string CjsonObject::GetItemFiled() -{ - if (cjson_ == nullptr) { - GLOGE("cjson is null"); - return ""; - } - if (cjson_->string == nullptr) { - GLOGE("cjson string is null"); - return ""; - } - return cjson_->string; -} - -int CjsonObject::Delete() -{ - if (cjson_ != nullptr) { - cJSON_Delete(cjson_); - } - return E_OK; -} - -} \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h deleted file mode 100644 index dcda3cb22cd7a612405ab681368d702fcfd9b796..0000000000000000000000000000000000000000 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef CJSON_OBJECT_H -#define CJSON_OBJECT_H - -#include -#include "cJSON.h" -#include "json_object.h" - -namespace DocumentDB { -class CjsonObject : public JsonObject{ -public: - CjsonObject () = default; - virtual ~CjsonObject () = default; - - int Parse(const std::string &str) override; - std::string Print() override; - CjsonObject* GetObjectItem(const std::string &field) override; - CjsonObject* GetArrayItem(const int index) override; - CjsonObject* GetNext(); - CjsonObject* GetChild(); - int DeleteItemFromObject(const std::string &field) override; - ResultValue* GetItemValue() override; - std::string GetItemFiled() override; - int Delete() override; -private: - cJSON *cjson_; -}; -} // DocumentDB -#endif // CJSON_OBJECT_H - diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/json_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19a75a555e2fc964d935485edbb30ac639a0a617 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/json_object.cpp @@ -0,0 +1,328 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "doc_errno.h" +#include "log_print.h" +#include "grd_format_config.h" +#include "json_object.h" + + +namespace DocumentDB { + +JsonObject::JsonObject() +{ + cjson_ = nullptr; + isClone_ = true; +} + +JsonObject::JsonObject(const JsonObject& newObj) +{ + cjson_ = newObj.cjson_; + isClone_ = true; +} + +JsonObject::~JsonObject() +{ + if (isClone_ == false) { + cJSON_Delete(cjson_); + } +} + +bool JsonObject::IsNull() +{ + if (cjson_ == nullptr) { + return true; + } + return false; +} + +int JsonObject::GetDeep(cJSON *cjson, int deep, int &maxDeep) +{ + if (cjson->child == nullptr) { + maxDeep = std::max(deep, maxDeep); + } + if (cjson->child != nullptr) { + GetDeep(cjson->child, deep + 1, maxDeep); + } + if (cjson->next != nullptr) { + GetDeep(cjson->next, deep, maxDeep); + } + return E_OK; +} + +int JsonObject::Init(const std::string &str) +{ + if (str.length() + 1 > JSON_LENS_MAX) { + return E_INVALID_ARGS; + } + const char *end = NULL; + cjson_ = cJSON_ParseWithOpts(str.c_str(), &end, true); + if (cjson_ == nullptr) { + return E_INVALID_ARGS; + } + if (cjson_->type != cJSON_Object) { + return E_INVALID_ARGS; + } + int deep = 0; + GetDeep(cjson_, 0, deep); + if (deep > JSON_DEEP_MAX) { + return E_INVALID_ARGS; + } + isClone_ = false; + return E_OK; +} + +std::string JsonObject::Print() +{ + if (cjson_ == nullptr) { + return ""; + } + char *ret = cJSON_PrintUnformatted(cjson_); + std::string str = ret; + free(ret); + return str; +} + +JsonObject JsonObject::GetObjectItem(const std::string &field, bool caseSensitive) +{ + if (cjson_ == nullptr) { + return JsonObject(); + } + JsonObject item; + if (caseSensitive) { + cJSON *cjsonItem = cJSON_GetObjectItemCaseSensitive(cjson_, field.c_str()); + } else { + cJSON *cjsonItem = cJSON_GetObjectItem(cjson_, field.c_str()); + item.cjson_ = cjsonItem; + } + return item; +} + +JsonObject JsonObject::GetArrayItem(const int index) +{ + if (cjson_ == nullptr) { + return JsonObject(); + } + JsonObject item; + auto cjsonItem = cJSON_GetArrayItem(cjson_, index); + if (cjsonItem == nullptr) { + return item; + } + item.cjson_ = cjsonItem; + return item; +} + +JsonObject JsonObject::GetNext() +{ + if (cjson_ == nullptr) { + return JsonObject(); + } + JsonObject next; + if (cjson_->next == nullptr) { + return JsonObject(); + } + next.cjson_ = cjson_->next; + return next; +} + +JsonObject JsonObject::GetChild() +{ + if (cjson_ == nullptr) { + return JsonObject(); + } + JsonObject child; + if (cjson_->child == nullptr) { + return JsonObject(); + } + child.cjson_ = cjson_->child; + return child; +} + +int JsonObject::DeleteItemFromObject(const std::string &field) +{ + if (field == "") { + return E_OK; + } + cJSON_DeleteItemFromObjectCaseSensitive(cjson_, field.c_str()); + return E_OK; +} + +ResultValue JsonObject::GetItemValue() +{ + if (cjson_ == nullptr) { + return ResultValue(); + } + ResultValue value; + switch (cjson_->type) { + case cJSON_False: { + value.valueType = ResultValue::ValueType::VALUE_FALSE; + } + break; + case cJSON_True: + { + value.valueType = ResultValue::ValueType::VALUE_TRUE; + } + break; + case cJSON_NULL: + { + value.valueType = ResultValue::ValueType::VALUE_NULL; + } + break; + case cJSON_Number: + { + value.valueType = ResultValue::ValueType::VALUE_NUMBER; + value.valueNumber = cjson_->valuedouble; + } + break; + case cJSON_String: + { + value.valueType = ResultValue::ValueType::VALUE_STRING; + value.valueString = cjson_->valuestring; + } + break; + case cJSON_Array: + { + value.valueType = ResultValue::ValueType::VALUE_ARRAY; + if (GetChild().IsNull() != true) { + auto item = GetChild(); + value.valueObject = &item; + } + } + break; + case cJSON_Object: + { + value.valueType = ResultValue::ValueType::VALUE_OBJECT; + if (GetChild().IsNull() != true) { + auto item = GetChild(); + value.valueObject = &item; + } + } + break; + default: + break; + } + + return value; +} + +std::string JsonObject::GetItemFiled() +{ + if (cjson_ == nullptr) { + return ""; + } + if (cjson_->string == nullptr) { + return ""; + } + return cjson_->string; +} + +JsonObject JsonObject::FindItem(const std::vector jsonPath) +{ + cJSON *cJsondataItem = cjson_; + if (jsonPath.size() != 0 && jsonPath[0] == "") { + return JsonObject(); + } + for (int i = 0; i < jsonPath.size(); i++) { + if (cJsondataItem->type == cJSON_Object) { + if (cJSON_GetObjectItem(cJsondataItem,jsonPath[i].c_str()) == nullptr) { + return JsonObject(); + } + cJSON *cJsondataTemp; + cJsondataTemp = cJSON_GetObjectItem(cJsondataItem,jsonPath[i].c_str()); + cJsondataItem = cJsondataTemp; + } + if (cJsondataItem->type == cJSON_Array) { + int nums = 0; + for (int j = 0; j < jsonPath[i].size(); j++) { + if (jsonPath[i][j]-'0' > 9 || jsonPath[i][j] - '0' < 0 || + jsonPath[i][j] - '0' > cJSON_GetArraySize(cJsondataItem)) { + break; + } + auto GetArrayRet = cJSON_GetArrayItem(cJsondataItem, jsonPath[i][j]-'0'); + if (typeid(GetArrayRet) == typeid(cJSON*)) { + cJsondataItem = GetArrayRet; + } + else { + if ( i != jsonPath.size() - 1) { + GLOGD("[cjson_object]=====>Patharg wrong"); + } + else { + return JsonObject(); + } + } + } + } + + } + JsonObject item; + item.cjson_ = cJsondataItem; + return item; +} + +int JsonObject::DeleteItemOnTarget(std::vector &path) +{ + cJSON *nodeFather; + cJSON *cJsondataRoot; + std::string lastString; + if (path.size()>0) { + lastString = path.back(); + path.pop_back(); + if (path.size() == 0) { + std::vector emptyPath; + auto cjsonObj = FindItem(emptyPath); + if (cjsonObj.IsNull() == true) { + return E_OK; + } + nodeFather = cjsonObj.cjson_; + cJsondataRoot = cjsonObj.cjson_; + path.emplace_back(lastString); + } + else { + std::vector fatherPath; + for (int i = 0; i < path.size() - 1; i++) { + fatherPath.emplace_back(path[i]); + } + auto foreObj = FindItem(fatherPath); + if (foreObj.IsNull() == true) { + return E_OK; + } + cJsondataRoot = foreObj.cjson_; + auto cjsonObj = FindItem(path); + if (cjsonObj.IsNull() == true) { + return E_OK; + } + nodeFather = cjsonObj.cjson_; + path.emplace_back(lastString); + } + } + if (nodeFather->type == cJSON_Object) { + if (cJSON_GetObjectItem(nodeFather, lastString.c_str()) != nullptr) { + cJSON_DeleteItemFromObject(nodeFather, lastString.c_str()); + } + else { + GLOGE("no item that can be deleted"); + } + } + if (nodeFather->type == cJSON_Array) { + if (cJSON_GetArrayItem(nodeFather, lastString[0] - '0') != nullptr) { + cJSON_DeleteItemFromArray(nodeFather, lastString[0] - '0'); + } + else { + GLOGE("no item that can be deleted"); + } + } + return E_OK; +} +} \ No newline at end of file