当前位置:网站首页>Using JSON in C language projects
Using JSON in C language projects
2022-07-28 12:41:00 【yi_ tianchou】
With the development of Internet of things , More and more things need to connect to the network to upload data , The server needs to connect to many types of terminals at the same time , The diversity of protocols is an important aspect of increasing the complexity of the server , At the same time, it also increases the complexity of maintenance , After weighing, the terminal finally adopts json data format .
Reason for use :
1、 standard Mainstream languages support json, convenient Terminal and server resolution
2、 Good scalability
3、 Easy to maintain
shortcoming :
It takes more bandwidth than binary data types
Usage method :
1、 download
https://sourceforge.net/projects/cjson/
There is a test package in the official project And use the tutorial
2、 take cjson package Included in the project #include "cJSON.h"
3、 Be careful cjson In the source file malloc and free Method replacement
void cJSON_InitHooks(cJSON_Hooks* hooks)
{
if (!hooks) { /* Reset hooks */
cJSON_malloc = vm_malloc;
cJSON_free = vm_free;
return;
}
cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:vm_malloc;
cJSON_free = (hooks->free_fn)?hooks->free_fn:vm_free;
}
I'm using vm_malloc and vm_free So I replaced it with my own method
4、json After converting to string , Release after the string is used because char* It's using malloc Created memory space
out = cJSON_Print(root); or out = cJSON_PrintUnformatted(root); stay out After use To manually release Otherwise, it will cause memory leakage
5、 Empathy , String rotation json after stay json After use, you should call cJSON_Delete() Release json object , because json Number is using malloc Created memory space Such as :
json = cJSON_Parse((char*)readBuf); After use cJSON_Delete(json );
6、 Common functions can be found on the Internet
establish and Value
边栏推荐
- MarkDown简明语法手册
- Using Arduino to develop esp8266 to build a development environment
- 西门子对接Leuze BPS_304i 笔记
- Developing NES games with C language (cc65) 08. Background collision
- 让arduino支持nuvotom新唐
- 用C语言开发NES游戏(CC65)02、什么是v-blank?
- 金山云冲刺港股拟双重主要上市:年营收90亿 为雷军力挺项目
- Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
- Newly released, the domestic ide developed by Alibaba is completely open source
- Not optimistic about Apple making AR, Luo Yonghao: I'll do it myself
猜你喜欢

GMT installation and use

HMS core audio editing service supports 7 kinds of audio effects to help one-stop audio processing

Newly released, the domestic ide developed by Alibaba is completely open source

FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be depreca

sqli-labs(less-8)

Markdown concise grammar manual

Unity 安装 Device Simulator

AVL树(平衡搜索树)

Distributed session solution

04 pyechars 地理图表(示例代码+效果图)
随机推荐
Multi Chain and multi currency wallet system development cross chain technology
How can a novice quickly complete the establishment of a website? Come to the free "fitting room" experience
金山云冲刺港股拟双重主要上市:年营收90亿 为雷军力挺项目
Most of the interfaces of Tiktok are already available, and more interfaces are still open. Please look forward to it
MarkDown简明语法手册
Implementation method of mouse hover, click and double click in ue4/5
SuperMap game engine license module division
Marketing play is changeable, and understanding the rules is the key!
用C语言开发NES游戏(CC65)10、游戏循环
On Governance and innovation | the openanolis sub forum of the 2022 open atom global open source summit was successfully held
AVL tree (balanced search tree)
MMA8452Q几种模式的初始化实例
图书馆自动预约脚本
Industry, University, research and application jointly build an open source talent ecosystem | the 2022 open atom global open source summit education sub forum was successfully held
First in the country! The two standards of "data product registration" formulated by insight technology and Shandong data were officially released
Redis implements distributed locks
开源汇智创未来 | 2022 开放原子全球开源峰会 OpenAtom openEuler 分论坛圆满召开
Knowledge points of MySQL (13)
04 pyechars 地理图表(示例代码+效果图)
AVL树(平衡搜索树)