}
+/*******************************************************************
+ *
+ * @brief wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @details
+ *
+ * Function : addNodeToObject
+ *
+ * Functionality:
+ * - wraps cJSON_AddNumberToObject cJSON library function
+ *
+ * @params[in] cJSON * parent, const char * nodeName, bool value
+ * @return pointer to cJSON object - success
+ * NULL - failure
+ *
+ * ****************************************************************/
+
+cJSON* JsonHelper::addNodeToObject(cJSON * parent, \
+ const char * nodeName, bool value)
+{
+ return cJSON_AddBoolToObject(parent, nodeName, (bool) value);
+}
+
/*******************************************************************
*
* @brief wraps cJSON_AddItemToObject cJSON library function
return cJSON_AddItemToObject(parent, nodeName, node);
}
+
/*******************************************************************
*
* @brief wraps cJSON_Delete cJSON library function
*
* ****************************************************************/
-char* JsonHelper::getValue(cJSON *json, const char *node)
+string JsonHelper::getValue(cJSON *json, const char *node)
{
cJSON *object;
- char * value = NULL;
+ string value = "";
object = cJSON_GetObjectItem(json, node);
if(object)
{
value = object->valuestring;
- O1_LOG("O1 VES : [ %s] : [%s]\n",node, value );
+ O1_LOG("O1 VES : [ %s] : [%s]\n",node, value.c_str() );
}
else
O1_LOG("O1 VES : node [ %s] not found\n",node);
std::fstream fs(fileName, std::ios::in | std::ios::binary);
if (!fs) {
- O1_LOG("O1 VES : json can NOT open file %s\n", fileName);
- return NULL;
+ O1_LOG("\nO1 JsonHelper : Cannot open file %s", fileName);
+ return NULL;
}
std::stringstream iss;
iss << fs.rdbuf();
- cJSON *json = cJSON_Parse(iss.str().c_str());
- return json;
+ cJSON *json = cJSON_Parse(iss.str().c_str());
+ return json;
+}
+
+cJSON* JsonHelper::createArray()
+{
+ return cJSON_CreateArray();
}
+cJSON_bool JsonHelper::addJsonNodeToArray(cJSON * array, cJSON* node)
+{
+ return cJSON_AddItemToArray(array, node);
+}
+
+
+
/**********************************************************************
End of file
**********************************************************************/