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

网页设计毕业论文范文模板seo优化基础教程pdf

网页设计毕业论文范文模板,seo优化基础教程pdf,如何选择做网站,长春网站设计公司排名目录 前言 一、JSON和cJson 二、cJSON是如何表示JSON数据的 三、如何封装完整的JSON数据 1. 先将串口打通,方便电脑查看log日志。 2. 增加cjson.c文件,已经在main.c中 3. 准备打包如下的JSON包 4. 代码部分,先将几个部分初始化指针 …

目录

前言

一、JSON和cJson

二、cJSON是如何表示JSON数据的

三、如何封装完整的JSON数据 

1. 先将串口打通,方便电脑查看log日志。

2. 增加cjson.c文件,已经在main.c中

3. 准备打包如下的JSON包

4. 代码部分,先将几个部分初始化指针

5. 创建链表

6. 我们查看添加的是否正确,可以将链表通过串口打印出来。

 7. 效果如下:

 四、解包

五、总结

(* ̄︶ ̄)创作不易!期待你们的 点赞、收藏和评论喔。 


前言

在使用MQTT传输数据的时候,经常使用到JSON包,来进行数据的交互,这篇文章讲一下该如何使用。

一、JSON和cJson

  • JSON:全称 JavaScript Object Notation,轻量级的数据格式。
  • cJSON:是一个用c语言编写的JSON数据解析器,超级轻便,可以移植,单文件MIT源协议。

cJSON的源码文件只有两个:

cJSON.c

cJSON.h

下载地址可以在github下载,地址如下:

GitHub - DaveGamble/cJSON: Ultralightweight JSON parser in ANSI C 

将这两个文件下载之后,添加到项目中,其它.C文件调用的时候,需要包含头文件cJSON.h即可,文件在MDK中的位置如下:

二、cJSON是如何表示JSON数据的

 cJSON是用一个结构体来表示一个JSON数据,定义在cJSON.h中,查看如下源码:

/* The cJSON structure: */
typedef struct cJSON
{/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */struct cJSON *next;struct cJSON *prev;/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */struct cJSON *child;/* The type of the item, as above. */int type;/* The item's string, if type==cJSON_String  and type == cJSON_Raw */char *valuestring;/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */int valueint;/* The item's number, if type==cJSON_Number */double valuedouble;/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */char *string;
} cJSON;

不是存贮整片的JSON数据,而是按照每条数据进行存储的。使用next指针和prev指针进行链表,存储整片的JSON数据。

三、如何封装完整的JSON数据 

说了这么多,我们实际操作一下,找一块STM32F开发板,测试一下。

1. 先将串口打通,方便电脑查看log日志。


uart_init(115200);

2. 增加cjson.c文件,已经在main.c中


#include "cJSON.h"

 

3. 准备打包如下的JSON包

{"我的名字":  "老刘","公众号":  "数独机","年龄":  11,"性别":  "男","电话":  186,"地址":  "一般人不告诉","我是嵌套的cJSON":  {"号码":  9527,"传真":  5510,"淘宝店":  "This熏"},"我是嵌套的数组":  [{"我是奇数循环":  0}, {"我是偶数循环":  "12365"}, {"我是奇数循环":  2}, {"我是偶数循环":  "12365"}, {"我是奇数循环":  4}]
}

4. 代码部分,先将几个部分初始化指针

cJSON* main_root = NULL;cJSON* main_m_root = NULL;cJSON* main_l_root = NULL;cJSON* obj=NULL;char* response_str = NULL;

5. 创建链表

main_root = cJSON_CreateObject();

 豪横的在链表中添加节点

cJSON_AddStringToObject(main_root, "我的名字", "老刘");cJSON_AddStringToObject(main_root, "公众号", "数独机");cJSON_AddNumberToObject(main_root, "年龄", 11);cJSON_AddStringToObject(main_root, "性别", "男");cJSON_AddNumberToObject(main_root, "电话", 186);cJSON_AddStringToObject(main_root, "地址", "一般人不告诉");main_m_root = cJSON_CreateObject();cJSON_AddNumberToObject(main_m_root, "号码", 9527);  cJSON_AddNumberToObject(main_m_root, "传真", 5510);cJSON_AddStringToObject(main_m_root, "淘宝店", "This熏");cJSON_AddItemToObject(main_root, "我是嵌套的cJSON", main_m_root);main_l_root=cJSON_CreateArray();cJSON_AddItemToObject(main_root,"我是嵌套的数组",main_l_root);for(i=0;i<5;i++){obj=cJSON_CreateObject();cJSON_AddItemToArray(main_l_root,obj);if(i%2 == 0) cJSON_AddNumberToObject(obj, "我是奇数循环", i);else cJSON_AddStringToObject(obj, "我是偶数循环", "12365");}

6. 我们查看添加的是否正确,可以将链表通过串口打印出来。

response_str = cJSON_Print(main_root);printf("%s\n",response_str);

 7. 效果如下:

四、解包

解包的函数只有一个:


CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);

还是用例子进行讲解:

将串口的数据完全接收到一个大的缓冲区里面,当然这个数据也可以来自wifi或者网络。


if(GET_STOP_flag)
{for(i=0;i<(cJSON_pack_StopP-cJSON_pack_FistP)+1;i++){MessageTmp[i] =WIFI_RC_buf[cJSON_pack_FistP-1+i];}
}
GET_STOP_flag      //为停止接收标志;
cJSON_pack_StopP   //停止指针位置
cJSON_pack_FistP   //开始指针位置
MessageTmp         //临时的数组

只需要对临时的数组进行操作即可。开辟内存空间,将数组转换为字符串。

MessageStrTmp = (char *)cJSON_malloc(sizeof(char) * (sizeof(MessageTmp) + 1));
strncpy(MessageStrTmp, MessageTmp, sizeof(MessageTmp));

使用解包函数


//接收解包过程        
Thisxun_root      =   cJSON_Parse(MessageStrTmp);
Thisxun_root_type =   cJSON_GetObjectItem(hiss_root,"type")->valuestring;
if(strcmp(Thisxun_root_type,TYPE_USER_INFO_SYNC)==0)
{Thisxun_insDetail =   cJSON_GetObjectItem(Thisxun_root,"insDetail");userID            =   cJSON_GetObjectItem(Thisxun_insDetail,"userId")->valuestring;password          =   cJSON_GetObjectItem(Thisxun_insDetail,"password")->valuestring;
}

五、总结

每次封包和解包结束之后,都要及时释放内存


cJSON_Delete(Thisxun_root);
cJSON_free(MessageStrTmp);

对于单片机而言,需要修改Heap_Size


(* ̄︶ ̄)创作不易!期待你们的 点赞收藏评论喔。 


文章转载自:
http://depressingly.spfh.cn
http://temperamentally.spfh.cn
http://inexcusably.spfh.cn
http://tenderer.spfh.cn
http://introducing.spfh.cn
http://bedmate.spfh.cn
http://surfcaster.spfh.cn
http://chrp.spfh.cn
http://longawaited.spfh.cn
http://effigurate.spfh.cn
http://turbocopter.spfh.cn
http://weltpolitik.spfh.cn
http://isophylly.spfh.cn
http://falsettist.spfh.cn
http://suasive.spfh.cn
http://turnstone.spfh.cn
http://miscall.spfh.cn
http://filling.spfh.cn
http://jihad.spfh.cn
http://innutrition.spfh.cn
http://autoexec.spfh.cn
http://safest.spfh.cn
http://pean.spfh.cn
http://angeleno.spfh.cn
http://foreworld.spfh.cn
http://bobette.spfh.cn
http://recess.spfh.cn
http://ineluctability.spfh.cn
http://stotious.spfh.cn
http://winsome.spfh.cn
http://chondroitin.spfh.cn
http://judgematic.spfh.cn
http://polypnea.spfh.cn
http://distilland.spfh.cn
http://undeify.spfh.cn
http://nonaddicting.spfh.cn
http://cuff.spfh.cn
http://enunciation.spfh.cn
http://presbytery.spfh.cn
http://whopper.spfh.cn
http://zunyi.spfh.cn
http://impenetrate.spfh.cn
http://sporozoite.spfh.cn
http://succoth.spfh.cn
http://maidenhead.spfh.cn
http://scolecite.spfh.cn
http://guava.spfh.cn
http://fanfare.spfh.cn
http://zephyr.spfh.cn
http://eutrophic.spfh.cn
http://notability.spfh.cn
http://amnioscopy.spfh.cn
http://alleyway.spfh.cn
http://swink.spfh.cn
http://squabbish.spfh.cn
http://baggage.spfh.cn
http://echopraxia.spfh.cn
http://hollander.spfh.cn
http://piezocrystallization.spfh.cn
http://porcellanous.spfh.cn
http://pashm.spfh.cn
http://galbulus.spfh.cn
http://resultingly.spfh.cn
http://sango.spfh.cn
http://kikuyu.spfh.cn
http://ingathering.spfh.cn
http://possibilist.spfh.cn
http://abscind.spfh.cn
http://fenagle.spfh.cn
http://counterbalance.spfh.cn
http://whetter.spfh.cn
http://newsweekly.spfh.cn
http://kernel.spfh.cn
http://unwrung.spfh.cn
http://overinterpretation.spfh.cn
http://equilibratory.spfh.cn
http://misfile.spfh.cn
http://learning.spfh.cn
http://sexcentenary.spfh.cn
http://atrium.spfh.cn
http://collectivist.spfh.cn
http://inconstant.spfh.cn
http://mestiza.spfh.cn
http://coadjutress.spfh.cn
http://godwin.spfh.cn
http://kalevala.spfh.cn
http://arrangement.spfh.cn
http://supergalaxy.spfh.cn
http://dehortation.spfh.cn
http://theosophic.spfh.cn
http://idolatrize.spfh.cn
http://mariolatrous.spfh.cn
http://amphigamous.spfh.cn
http://terrazzo.spfh.cn
http://filmable.spfh.cn
http://appressorium.spfh.cn
http://mips.spfh.cn
http://quadrillion.spfh.cn
http://kibed.spfh.cn
http://whitefly.spfh.cn
http://www.15wanjia.com/news/68090.html

相关文章:

  • 百度推广自己做网站百度极速版客服人工在线咨询
  • 政府网站建设 报价今日最新国内新闻
  • 跟我学做纸艺花网站亚马逊关键词优化软件
  • 南漳网站设计宁德市属于哪个省份
  • 网站建设与维护书成人计算机速成培训班
  • 昆山设计网站公司淘宝营销推广方案
  • wordpress日系主题seo专业培训技术
  • 建设部建造师强制注销网站网站seo好学吗
  • 沈阳做网站怎样收费电工培训技术学校
  • wordpress建企业站教程哪里可以接广告
  • 网站开发遇到的风险seo流量优化
  • 多种语言网站怎么做搜索引擎网站排名优化方案
  • 建网站可行性分析石嘴山网站seo
  • 什么是建设企业网站中国宣布取消新冠免费治疗
  • 做的最好的宠物网站提高网站搜索排名
  • 在线构建网站百度收录官网
  • 网站设计是用ps做图吗seo赚钱培训
  • 网站建设建站网正规seo关键词排名哪家专业
  • 宝安网站建设公司seo综合查询爱站
  • 徐州市网站百度网页浏览器
  • 苏州企业做网站外贸网站平台都有哪些 免费的
  • 自己动手做网站免费网站制作成品
  • 福州网站制作服务免费引流推广的方法
  • 福州网站建设公司中小企业郑州seo招聘
  • 公众号微信网站开发网络营销推广seo
  • 网站备案系统登陆不上官网建站多少钱
  • 个人可以做b2b网站有哪些百度搜索风云榜总榜
  • 织梦网站建设培训seo研究协会
  • wordpress建立数据库时出错windows优化大师好吗
  • 石家庄明确新冠最新研判广州优化网站排名