MCPcopy Create free account
hub / github.com/Bwar/CJsonObject / AddEmptySubArray

Method AddEmptySubArray

CJsonObject.cpp:154–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154bool 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
198bool CJsonObject::GetKey(std::string& strKey)
199{

Callers 1

mainFunction · 0.80

Calls 4

cJSON_CreateObjectFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_CreateArrayFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85

Tested by

no test coverage detected