28 #include "AampUtils.h"
33 AampJsonObject::AampJsonObject() : mParent(NULL), mJsonObj()
35 mJsonObj = cJSON_CreateObject();
38 AampJsonObject::AampJsonObject(
const std::string& jsonStr) : mParent(NULL), mJsonObj()
40 mJsonObj = cJSON_Parse(jsonStr.c_str());
48 AampJsonObject::AampJsonObject(
const char* jsonStr) : mParent(NULL), mJsonObj()
50 mJsonObj = cJSON_Parse(jsonStr);
58 AampJsonObject::~AampJsonObject()
62 cJSON_Delete(mJsonObj);
75 res =
add(name, cJSON_CreateString(value.c_str()));
79 res =
add(name, std::vector<uint8_t>(value.begin(), value.end()), encoding);
90 return add(name, std::string(value), encoding);
98 cJSON* arr = cJSON_CreateArray();
99 for (
auto value : values)
101 cJSON_AddItemToArray(arr, cJSON_CreateString(value.c_str()));
103 return add(name, arr);
117 std::string strValue(values.begin(), values.end());
118 res =
add(name, cJSON_CreateString(strValue.c_str()));
124 const char *encodedResponse =
base64_Encode((
const unsigned char*)&values[0], values.size());
125 if (encodedResponse != NULL)
127 res =
add(name, cJSON_CreateString(encodedResponse));
128 free((
void*)encodedResponse);
136 if (encodedResponse != NULL)
138 res =
add(name, cJSON_CreateString(encodedResponse));
139 free((
void*)encodedResponse);
157 cJSON_AddItemToObject(mJsonObj, name.c_str(), value.mJsonObj);
158 value.mParent =
this;
167 cJSON *arr = cJSON_CreateArray();
168 for (
auto& obj : values)
170 cJSON_AddItemToArray(arr, obj->mJsonObj);
173 return add(name, arr);
185 cJSON_AddItemToObject(mJsonObj, name.c_str(), value);
195 cJSON_AddItemToObject(mJsonObj, name.c_str(), cJSON_CreateBool(value));
204 cJSON_AddItemToObject(mJsonObj, name.c_str(), cJSON_CreateNumber(value));
213 cJSON_AddItemToObject(mJsonObj, name.c_str(), cJSON_CreateNumber(value));
222 cJSON_AddItemToObject(mJsonObj, name.c_str(), cJSON_CreateNumber(value));
231 this->mParent = parent;
232 this->mJsonObj = object;
242 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
243 bool retValue =
false;
246 retValue = value.set(
this, strObj);
256 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
260 char *strValue = cJSON_GetStringValue(strObj);
275 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
276 bool retValue =
false;
282 value = (int)strObj->valuedouble;
293 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
294 cJSON *
object = NULL;
296 cJSON_ArrayForEach(
object, strObj)
298 char *strValue = cJSON_GetStringValue(
object);
301 values.push_back(std::string(strValue));
314 std::string strValue;
316 if (
get(name, strValue))
324 values.insert(values.begin(), strValue.begin(), strValue.end());
330 size_t decodedSize = 0;
331 const unsigned char *decodedResponse =
base64_Decode(strValue.c_str(), &decodedSize, strValue.length());
332 if (decodedResponse != NULL)
334 values.insert(values.begin(), decodedResponse, decodedResponse + decodedSize);
336 free((
void *)decodedResponse);
343 size_t decodedSize = 0;
344 const unsigned char *decodedResponse =
aamp_Base64_URL_Decode(strValue.c_str(), &decodedSize, strValue.length());
345 if (decodedResponse != NULL)
347 values.insert(values.begin(), decodedResponse, decodedResponse + decodedSize);
349 free((
void *)decodedResponse);
367 char *jsonString = cJSON_Print(mJsonObj);
368 if (NULL != jsonString)
370 std::string retStr(jsonString);
371 cJSON_free(jsonString);
382 char *jsonString = cJSON_PrintUnformatted(mJsonObj);
383 if (NULL != jsonString)
385 std::string retStr(jsonString);
386 cJSON_free(jsonString);
397 std::string jsonOutputStr =
print();
398 (void)data.insert(data.begin(), jsonOutputStr.begin(), jsonOutputStr.end());
406 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
410 retVal = cJSON_IsArray(strObj);
420 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
424 retVal = cJSON_IsString(strObj);
434 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
438 retVal = cJSON_IsNumber(strObj);
448 cJSON *strObj = cJSON_GetObjectItem(mJsonObj, name.c_str());
452 retVal = cJSON_IsObject(strObj);