| 108 | } |
| 109 | |
| 110 | bool CJsonObject::AddEmptySubObject(const std::string& strKey) |
| 111 | { |
| 112 | cJSON* pFocusData = NULL; |
| 113 | if (m_pJsonData != NULL) |
| 114 | { |
| 115 | pFocusData = m_pJsonData; |
| 116 | } |
| 117 | else if (m_pExternJsonDataRef != NULL) |
| 118 | { |
| 119 | pFocusData = m_pExternJsonDataRef; |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | m_pJsonData = cJSON_CreateObject(); |
| 124 | m_pKeyTravers = m_pJsonData; |
| 125 | pFocusData = m_pJsonData; |
| 126 | } |
| 127 | |
| 128 | if (pFocusData == NULL) |
| 129 | { |
| 130 | m_strErrMsg = "json data is null!"; |
| 131 | return(false); |
| 132 | } |
| 133 | if (pFocusData->type != cJSON_Object) |
| 134 | { |
| 135 | m_strErrMsg = "not a json object! json array?"; |
| 136 | return(false); |
| 137 | } |
| 138 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL) |
| 139 | { |
| 140 | m_strErrMsg = "key exists!"; |
| 141 | return(false); |
| 142 | } |
| 143 | cJSON* pJsonStruct = cJSON_CreateObject(); |
| 144 | if (pJsonStruct == NULL) |
| 145 | { |
| 146 | m_strErrMsg = std::string("create sub empty object error!"); |
| 147 | return(false); |
| 148 | } |
| 149 | cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct); |
| 150 | m_pKeyTravers = pFocusData; |
| 151 | return(true); |
| 152 | } |
| 153 | |
| 154 | bool CJsonObject::AddEmptySubArray(const std::string& strKey) |
| 155 | { |
no test coverage detected