1

I want to parse the json {"endtime":"<timestamp>", "status":"on"} and the timestamp contains something like 3/27/2019 7:40:47 AM.

my code is given below:

cJSON * root   = cJSON_Parse(buffer);
cJSON * name = cJSON_GetObjectItem(root, "status");
cJSON * sum = cJSON_GetObjectItem(root, "endtime");
res = strcmp(name->valuestring, "ON");
printf("timestamp = %s \n", sum->valuestring);
char str1[20];
char str[5];
strcpy(str, name->valuestring);
strcpy(str1, sum->valuestring);

I want to check whether the status contain on/off and get timestamp from endtime.

Is this the right way to parse?

Mikev
  • 2,012
  • 1
  • 15
  • 27
Nazna AA
  • 11
  • 3
  • Your variable names leave something to be desired, and you should be using `cJSON_GetObjectItemCaseSensitive()` in new code. Plus of course error checking. – Shawn Apr 01 '19 at 11:28

0 Answers0