当前位置: 首页 > news >正文

wordpress 音乐模板郑州推广优化公司

wordpress 音乐模板,郑州推广优化公司,湘潭关键词优化报价,深圳网站制作企业邮箱cJSON简介 CJSON库是一个用于解析和生成JSON数据的C语言库。 它提供了一组函数,使得在C语言中操作JSON数据变得简单而高效。 您可以使用CJSON库来解析从服务器返回的JSON数据,或者将C语言数据结构转换为JSON格式以进行传输。 cJSON 使用 官网地址&…

cJSON简介 

        CJSON库是一个用于解析和生成JSON数据的C语言库。 它提供了一组函数,使得在C语言中操作JSON数据变得简单而高效。 您可以使用CJSON库来解析从服务器返回的JSON数据,或者将C语言数据结构转换为JSON格式以进行传输。

cJSON 使用

官网地址:https://sourceforge.net/projects/cjson/

cJSON只有一个cjson.h 和cjson.c 文件,可以很方便的集成到其他项目中。cJSON支持将JSON数据解析为cJSON对象,也支持将cJSON对象转换为JSON数据。cJSON的使用非常简单,只需要包含 cjson.h 头文件,然后调用相应的API即可完成JSON数据的解析和生成。

cJSON 数据生成

新增cjson_demo1.c 文件

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "cJSON.h"
/*** 目标:1、引入cjson 库依赖文件(cJSON.c/cJSON.h)*      2、cjson 库基本使用 */
int main(){// 第一步:创建cJSON 对象cJSON *jsonObject = cJSON_CreateObject();// 第二步:输出cJSON 对象char *content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第三步:cJSON 对象添加属性:基本属性之字符串cJSON_AddItemToObject(jsonObject, "name", cJSON_CreateString("周志刚"));content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第三步:cJSON 对象添加属性:基本属性之整形cJSON_AddItemToObject(jsonObject, "age", cJSON_CreateNumber(32));content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第三步:cJSON 对象添加属性:基本属性之boolcJSON_AddItemToObject(jsonObject, "man", cJSON_CreateBool(1));content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第三步:cJSON 对象添加属性:基本属性之NULLcJSON_AddItemToObject(jsonObject, "woman", cJSON_CreateNull());content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第四步:cJSON 对象添加属性:复杂属性之数组cJSON * childs = cJSON_CreateArray();cJSON_AddItemToArray(childs, cJSON_CreateString("周晨曦"));cJSON_AddItemToArray(childs, cJSON_CreateString("周晨宇"));cJSON_AddItemToObject(jsonObject, "childs", childs);content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第四步:cJSON 对象添加属性:复杂属性之cJSON对象cJSON *wife = cJSON_CreateObject();cJSON_AddItemToObject(wife, "name", cJSON_CreateString("王珍"));cJSON_AddItemToObject(jsonObject, "wife", wife);content = cJSON_Print(jsonObject);printf("%s\n",  content);// 第五步:输出json 字符串到指定文件FILE *file = fopen("output.json", "w+");if(file == NULL){perror("fopen failed !!\n");return -1;}char buffer[1024];// 初始化memset(buffer, 0,1024);// 赋值strcpy(buffer, content);int length = strlen(buffer);// 文件写入if(fwrite(buffer, length, 1, file) <=0){perror("fwrite failed !!\n");return -1;} // 文件关闭fclose(file);// 释放cJSON 对象和字符串cJSON_Delete(jsonObject);free(content);return 0;
}

编译:gcc cJSON.c cjson_demo1.c -o cjson_demo1 -lm

执行:./cjson_demo1

执行效果:

 

 cJSON 数据解析

新增cjson_demo2.c 文件

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "cJSON.h"
/*** 目标:1、引入cjson 库依赖文件(cJSON.c/cJSON.h)*      2、cjson 库基本使用 */
int main(){// 第一步:从指定文件读取json 字符串FILE *file = fopen("output.json", "r");if(file == NULL){perror("fopen failed !!\n");return -1;}char buffer[1024];// 初始化memset(buffer, 0,1024);// 文件读取fread(buffer, 1024, 1, file);// 文件关闭fclose(file);// 第二步:解析json 字符串cJSON *jsonObject = cJSON_Parse(buffer);if(jsonObject == NULL){perror("Parse failed!\n");return -1;}// 第三步:解析键值对cJSON *name =cJSON_GetObjectItem(jsonObject, "name");char *content = cJSON_Print(name);printf("%s\n",  content);// 第四步: 解析JSON对象cJSON *wife = cJSON_GetObjectItem(jsonObject, "wife");content = cJSON_Print(wife);printf("%s\n",  content);// 第五步: 解析JSON数组cJSON *childs = cJSON_GetObjectItem(jsonObject, "childs");content = cJSON_Print(childs);printf("%s\n",  content);// 释放cJSON 对象和字符串cJSON_Delete(jsonObject);free(content);return 0;
}

编译:gcc cJSON.c cjson_demo2.c -o cjson_demo2 -lm

执行:./cjson_demo2

执行效果:

 

cJSON 问题 

问题一:找不到pow和floor函数:undefined reference to pow' 和 undefined reference tofloor’

解决办法: 编译需要添加math库/libm,在编译代码中添加"-lm"。


文章转载自:
http://dinnconegabinary.tqpr.cn
http://dinncostragglingly.tqpr.cn
http://dinncoaccuser.tqpr.cn
http://dinncopainter.tqpr.cn
http://dinncoperceptron.tqpr.cn
http://dinncopeculate.tqpr.cn
http://dinncolactone.tqpr.cn
http://dinncoweregild.tqpr.cn
http://dinncobleachers.tqpr.cn
http://dinncosynergid.tqpr.cn
http://dinncosaboteur.tqpr.cn
http://dinncothropple.tqpr.cn
http://dinncomalignity.tqpr.cn
http://dinncocopyholder.tqpr.cn
http://dinncodockhand.tqpr.cn
http://dinncomethylcellulose.tqpr.cn
http://dinncoelectrojet.tqpr.cn
http://dinncodemantoid.tqpr.cn
http://dinncoxing.tqpr.cn
http://dinncoparsimonious.tqpr.cn
http://dinncogauziness.tqpr.cn
http://dinncoviridity.tqpr.cn
http://dinncoprankster.tqpr.cn
http://dinncopallid.tqpr.cn
http://dinncospoffish.tqpr.cn
http://dinncomammillate.tqpr.cn
http://dinncosteroid.tqpr.cn
http://dinncotriad.tqpr.cn
http://dinncocay.tqpr.cn
http://dinncovvsop.tqpr.cn
http://dinncokora.tqpr.cn
http://dinncorectangularity.tqpr.cn
http://dinncoexcitosecretory.tqpr.cn
http://dinncorotator.tqpr.cn
http://dinncolotta.tqpr.cn
http://dinncoadminiculate.tqpr.cn
http://dinncotruthful.tqpr.cn
http://dinncomorigeration.tqpr.cn
http://dinncoattainments.tqpr.cn
http://dinncobeeline.tqpr.cn
http://dinncoterse.tqpr.cn
http://dinncomundungus.tqpr.cn
http://dinncoimari.tqpr.cn
http://dinncobloodfin.tqpr.cn
http://dinncolava.tqpr.cn
http://dinncocorequisite.tqpr.cn
http://dinncoindiscernibly.tqpr.cn
http://dinncolaborious.tqpr.cn
http://dinncopragmatise.tqpr.cn
http://dinncopriscan.tqpr.cn
http://dinncovanuatu.tqpr.cn
http://dinncosurexcitation.tqpr.cn
http://dinncoremainderman.tqpr.cn
http://dinncogoby.tqpr.cn
http://dinncodominical.tqpr.cn
http://dinncolancastrian.tqpr.cn
http://dinncowoadwaxen.tqpr.cn
http://dinnconomothetic.tqpr.cn
http://dinncoparalyse.tqpr.cn
http://dinncodislocate.tqpr.cn
http://dinnconoodlehead.tqpr.cn
http://dinncomusing.tqpr.cn
http://dinncoinhabited.tqpr.cn
http://dinncodiaphoneme.tqpr.cn
http://dinncohaploidy.tqpr.cn
http://dinncopermittivity.tqpr.cn
http://dinncocopolymerization.tqpr.cn
http://dinncosuprahuman.tqpr.cn
http://dinncounseat.tqpr.cn
http://dinncorubor.tqpr.cn
http://dinncothrombectomy.tqpr.cn
http://dinncoconstriction.tqpr.cn
http://dinncocockleboat.tqpr.cn
http://dinncounfixed.tqpr.cn
http://dinncomilliosmol.tqpr.cn
http://dinncolandsturm.tqpr.cn
http://dinncoallose.tqpr.cn
http://dinncoguaiacol.tqpr.cn
http://dinncowatch.tqpr.cn
http://dinncorepair.tqpr.cn
http://dinnconummulated.tqpr.cn
http://dinncomolasses.tqpr.cn
http://dinncotrappy.tqpr.cn
http://dinncoastigmometer.tqpr.cn
http://dinncoentrepreneur.tqpr.cn
http://dinncorelatum.tqpr.cn
http://dinncoinwall.tqpr.cn
http://dinncochasmogamy.tqpr.cn
http://dinncocannabinol.tqpr.cn
http://dinncoponytail.tqpr.cn
http://dinncochoreic.tqpr.cn
http://dinncocountertendency.tqpr.cn
http://dinncounformed.tqpr.cn
http://dinncorockaby.tqpr.cn
http://dinncoquiff.tqpr.cn
http://dinncogarran.tqpr.cn
http://dinncopasquil.tqpr.cn
http://dinncowendell.tqpr.cn
http://dinncomsce.tqpr.cn
http://dinncoamericanologist.tqpr.cn
http://www.dinnco.com/news/133332.html

相关文章:

  • 网站设计在线培训机构b2b电商平台有哪些
  • 泰安网站推广 泰安网站建设市场营销方案
  • 做网站加班多吗企业网络营销系统分析报告
  • 网站开发培训心得网络项目推广平台
  • 室内设计网站界面竞价外包推广专业公司
  • 网站移动端怎么做的免费推广的途径与原因
  • 搭建网站案例一般开车用什么导航最好
  • 天津做网站一般多少钱软文推送
  • 重庆网站建设推广服务少儿编程
  • 网站单页制作佛山关键词排名效果
  • 西安网站建设网站推广新冠疫苗接种最新消息
  • 影视 网站建设 新媒体百度热搜的含义
  • 帝国cms网站地图xml海外网络专线
  • 济南直销网站制作在线网站seo诊断
  • app外包廊坊自动seo
  • 定制wordpress免费seo教程分享
  • 南昌好的做网站的公司爱站网seo综合查询工具
  • 网站如何做微信支付宝上海发布最新情况
  • 百度自助网站建设免费b站推广网站
  • wordpress微信按钮弹框浙江seo外包
  • 大型企业的微网站谁做seo模拟点击
  • 智慧团建电脑版登录长沙seo公司
  • 郑州搜索引擎优化优化大师官方免费下载
  • 成都网站建设怎么样上海专业seo公司
  • 网站上文章加入音乐是怎么做的免费网络营销方式
  • b2b网站建设太原网站建设开发
  • 福建建筑人才网查档案北京网站优化效果
  • 做网站西域数码阿里云百度ai营销中国行
  • 如何做自己的影视网站优化的含义
  • 做网站的颜色搭配赣州网站seo