-
**[cJSON使用详细教程 一个轻量级C语言JSON解析器](https://blog.csdn.net/Mculover666/article/details/103796256)**
解释JSON
解释json: data = cJSON_Parse(string)
键取值: url = cJSON_GetObjectItem(data)
值转文本: text = url→valuestring
值转数字: text = url→valueint
释放资源: cJSON_Delete(data)
#include <stdio.h>
#include <stdlib.h>
#include <cjson/cJSON.h>
extern char *body;
extern int get(char *url);
int main() {
char *text;
cJSON* data = NULL;
cJSON* headers = NULL;
cJSON* url = NULL;
body = (char *)malloc(0);
get("http://httpbin.org/get");
data = cJSON_Parse(body);
headers = cJSON_GetObjectItem(data, "headers");
text = cJSON_Print(headers);
url = cJSON_GetObjectItem(data, "url");
printf("%s\n", url->valuestring);
free(body);
cJSON_Delete(data);
return 0;
}