This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

cJSON error

Dear Sir.

I am using the cJSON driver .

When it comes to string it works fine .

However when I use integer and swap the lines

//cJSON_AddStringToObject(root, "payload", payload);
cJSON_AddNumberToObject(root, "payload", 1243);

I can use the debug , The program is halted.

Please Advise.

cJSON * createJsonFromParams(void)
{
  
  char * command = "periodic" ;//  "holter"  "holtersm" "spot"   "time"
  char * type  = "12";
//  char * start_time  = "1845";
//  char * duration  = "104";
//  char * rest  = "29";
//  char * stop_time  = "27000";
  char * payload =  "Etrog2020";
//  int * payload = 123456; //"Etrog2020"; //  {0x06,0x05,0x04,0x03,0x02,0x01}; //
//  cJSON *number_item = cJSON_CreateNumber(1942);

  cJSON *root = cJSON_CreateObject();
  cJSON_AddStringToObject(root, "command", command);
  cJSON_AddStringToObject(root, "type", type);
//  cJSON_AddStringToObject(root, "start_time", start_time);
//  cJSON_AddStringToObject(root, "duration", duration);
//  cJSON_AddStringToObject(root, "rest", rest);
//  cJSON_AddStringToObject(root, "stop_time", stop_time);



  cJSON_AddStringToObject(root, "payload", payload);
//  cJSON_AddNumberToObject(root, "payload", 1243);

  
  return root;
}

Parents Reply Children
No Data
Related