【发布时间】:2019-01-29 09:49:10
【问题描述】:
我正在尝试使用 cJSON 解析由网络服务器上的 CGI 文件接收的 JSON 文件,但是 JSON 中的第一个数字不断更改为 0。
我编写了一小段代码来测试它:
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;
}
通过查询字符串将 JSON {"test":123, "test2":123} 传递给 this 会导致程序输出以下内容:
0
123
{"test":0, "test2":123}
我完全不知道我在这里做错了什么,如果有人能给我一些关于问题可能是什么的想法,我将不胜感激。
【问题讨论】: