| 152 | } |
| 153 | |
| 154 | bool CJsonObject::AddEmptySubArray(const std::string& strKey) |
| 155 | { |
| 156 | cJSON* pFocusData = NULL; |
| 157 | if (m_pJsonData != NULL) |
| 158 | { |
| 159 | pFocusData = m_pJsonData; |
| 160 | } |
| 161 | else if (m_pExternJsonDataRef != NULL) |
| 162 | { |
| 163 | pFocusData = m_pExternJsonDataRef; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | m_pJsonData = cJSON_CreateObject(); |
| 168 | m_pKeyTravers = m_pJsonData; |
| 169 | pFocusData = m_pJsonData; |
| 170 | } |
| 171 | |
| 172 | if (pFocusData == NULL) |
| 173 | { |
| 174 | m_strErrMsg = "json data is null!"; |
| 175 | return(false); |
| 176 | } |
| 177 | if (pFocusData->type != cJSON_Object) |
| 178 | { |
| 179 | m_strErrMsg = "not a json object! json array?"; |
| 180 | return(false); |
| 181 | } |
| 182 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL) |
| 183 | { |
| 184 | m_strErrMsg = "key exists!"; |
| 185 | return(false); |
| 186 | } |
| 187 | cJSON* pJsonStruct = cJSON_CreateArray(); |
| 188 | if (pJsonStruct == NULL) |
| 189 | { |
| 190 | m_strErrMsg = std::string("create sub empty array error!"); |
| 191 | return(false); |
| 192 | } |
| 193 | cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct); |
| 194 | m_pKeyTravers = pFocusData; |
| 195 | return(true); |
| 196 | } |
| 197 | |
| 198 | bool CJsonObject::GetKey(std::string& strKey) |
| 199 | { |
no test coverage detected