| 165 | } |
| 166 | |
| 167 | bool CJsonObject::AddEmptySubArray(const std::string& strKey) |
| 168 | { |
| 169 | cJSON* pFocusData = NULL; |
| 170 | if (m_pJsonData != NULL) |
| 171 | { |
| 172 | pFocusData = m_pJsonData; |
| 173 | } |
| 174 | else if (m_pExternJsonDataRef != NULL) |
| 175 | { |
| 176 | pFocusData = m_pExternJsonDataRef; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | m_pJsonData = cJSON_CreateObject(); |
| 181 | m_pKeyTravers = m_pJsonData; |
| 182 | pFocusData = m_pJsonData; |
| 183 | } |
| 184 | |
| 185 | if (pFocusData == NULL) |
| 186 | { |
| 187 | m_strErrMsg = "json data is null!"; |
| 188 | return(false); |
| 189 | } |
| 190 | if (pFocusData->type != cJSON_Object) |
| 191 | { |
| 192 | m_strErrMsg = "not a json object! json array?"; |
| 193 | return(false); |
| 194 | } |
| 195 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL) |
| 196 | { |
| 197 | m_strErrMsg = "key exists!"; |
| 198 | return(false); |
| 199 | } |
| 200 | cJSON* pJsonStruct = cJSON_CreateArray(); |
| 201 | if (pJsonStruct == NULL) |
| 202 | { |
| 203 | m_strErrMsg = std::string("create sub empty array error!"); |
| 204 | return(false); |
| 205 | } |
| 206 | cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct); |
| 207 | m_pKeyTravers = pFocusData; |
| 208 | return(true); |
| 209 | } |
| 210 | |
| 211 | bool CJsonObject::GetKey(std::string& strKey) |
| 212 | { |
nothing calls this directly
no test coverage detected