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

Method AddEmptySubObject

CJsonObject.cpp:110–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110bool 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
154bool CJsonObject::AddEmptySubArray(const std::string& strKey)
155{

Callers 1

mainFunction · 0.80

Calls 3

cJSON_CreateObjectFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85

Tested by

no test coverage detected