[root@localhost /]# cat myjson.c
#include
#include
#include
#include "v_json.h"
int main()
{
char *text = NULL;
char body[1024] = {0};
char body2[1024] = {0};
char cmd[1024] = {0};
cJSON * root = cJSON_CreateObject();
int i = 0;
int j = 0;
cJSON_AddItemToObject(root, "type", cJSON_CreateString("vm"));
cJSON_AddItemToObject(root, "action", cJSON_CreateString("approval"));
cJSON_AddItemToObject(root, "vmName", cJSON_CreateString("FW"));
cJSON_AddItemToObject(root, "result", cJSON_CreateString("0"));
text = cJSON_Print(root);
strcpy(body, text);
if(root != NULL)
cJSON_Delete(root);
if(text != NULL)
free(text);
for(i=0; i
if(body[i] != '\"')
{
body2[j] = body[i];
}
else
{
strcat(body2,"\\");
strcat(body2,"\"");
j++;
}
j++;
}
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),"/software/bin/vetrix_mqtt tcp://%s:1883 %s \"%s\"", "192.168.27.245", "4e1cc587-4c60-46dc-8eaf-33b8aafdcc46", body2);
printf("%s\n",cmd);
system(cmd);
return 0;
}
[root@localhost /]#