json串:
{
- "list":[
- "hello",
- "world"
}
代码 :
int func(char *sn)
{
int ret = 0;
cJSON *root, *list;
FILE *fp = fopen("a.txt", "r");
if(!fp) {
printf("open sn file failed!\n");
return -1;
}
struct stat st;
if (fstat("a.txt", &st) == -1) {
fclose(fp);
return -1;
}
char *buffer = (char*)malloc(st.st_size);
if(buffer == NULL) {
fclose(fp);
return -1;
}
ret = fread(buffer, 1, st.st_size, fp);
if(ret != st.st_size) {
printf("fread sn file failed!\n");
goto err1;
}
if ((root = cJSON_Par