| 121 | } |
| 122 | |
| 123 | bool CJsonObject::AddEmptySubObject(const std::string& strKey) |
| 124 | { |
| 125 | cJSON* pFocusData = NULL; |
| 126 | if (m_pJsonData != NULL) |
| 127 | { |
| 128 | pFocusData = m_pJsonData; |
| 129 | } |
| 130 | else if (m_pExternJsonDataRef != NULL) |
| 131 | { |
| 132 | pFocusData = m_pExternJsonDataRef; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | m_pJsonData = cJSON_CreateObject(); |
| 137 | m_pKeyTravers = m_pJsonData; |
| 138 | pFocusData = m_pJsonData; |
| 139 | } |
| 140 | |
| 141 | if (pFocusData == NULL) |
| 142 | { |
| 143 | m_strErrMsg = "json data is null!"; |
| 144 | return(false); |
| 145 | } |
| 146 | if (pFocusData->type != cJSON_Object) |
| 147 | { |
| 148 | m_strErrMsg = "not a json object! json array?"; |
| 149 | return(false); |
| 150 | } |
| 151 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL) |
| 152 | { |
| 153 | m_strErrMsg = "key exists!"; |
| 154 | return(false); |
| 155 | } |
| 156 | cJSON* pJsonStruct = cJSON_CreateObject(); |
| 157 | if (pJsonStruct == NULL) |
| 158 | { |
| 159 | m_strErrMsg = std::string("create sub empty object error!"); |
| 160 | return(false); |
| 161 | } |
| 162 | cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct); |
| 163 | m_pKeyTravers = pFocusData; |
| 164 | return(true); |
| 165 | } |
| 166 | |
| 167 | bool CJsonObject::AddEmptySubArray(const std::string& strKey) |
| 168 | { |
nothing calls this directly
no test coverage detected