C语言环境下JSON格式的转化

版权声明:如有错误或侵权,请指正。 https://blog.csdn.net/weixin_44101331/article/details/86627705

转化步骤

1. 下载CJSON库

2. 添加到工程中

3. 在主函数中添加代码

#include<stdio.h>
#include<stdlib.h>
#include"cJSON.h"

int main(void)
{
    char *data = "{\"love\":[\"LOL\",\"Go shopping\"]}";
    //从缓冲区中解析出JSON结构
    cJSON * json= cJSON_Parse(data);
    
    //将传入的JSON结构转化为字符串 并打印
    char *json_data = NULL;
    printf("data:%s\n",json_data = cJSON_Print(json));
    
    free(json_data);
    //将JSON结构所占用的数据空间释放
    cJSON_Delete(json);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44101331/article/details/86627705
今日推荐