I'm trying to parse a JSON file received by a CGI file on a webserver using cJSON however the first number in the JSON keeps getting changed to 0.
I've made a short piece of code which I'm using to test this:
int main(int argc, char *argv[])
{
cJSON *pstReq;
char *pcReq = getenv("QUERY_STRING");
printf("Content-Type: application/json\n\n");
URLDecode(pcReq) /* Decodes the query string to JSON string */
pstReq = cJSON_Parse(pstReq);
printf("%d\n", cJSON_GetObjectItem(pstReq, "test")->valueint);
printf("%d\n", cJSON_GetObjectItem(pstReq, "test2")->valueint);
printf(cJSON_Print(pstReq));
return EXIT_SUCCESS;
}
Passing the JSON {"test":123, "test2":123} into this through the query string causes the program to output this:
0
123
{"test":0, "test2":123}
I have absolutely no idea what I'm doing wrong here if anybody could give me some idea of what the problem might be I'd greatly appreciate it.