当前位置:网站首页>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
边栏推荐
- 通过Jenkins 拉取服务器代码 权限不足问题及其他注意事项
- 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
- Newly released, the domestic ide developed by Alibaba is completely open source
- Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
- 用C语言开发NES游戏(CC65)06、精灵
- How to build knowledge management system in enterprises and institutions
- [Nuxt 3] (十二) 项目目录结构 3
- SQL injection less26 (filter spaces and comments, and use error injection without spaces)
- Baidu map API adds information window circularly. The window only opens at the last window position and the window information content is the same solution
- Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center
猜你喜欢

04 pyechars 地理图表(示例代码+效果图)

用C语言开发NES游戏(CC65)09、滚动

Design a thread pool

If you don't roll the golden nine and silver ten, it's too late

MarkDown简明语法手册

HC-05蓝牙模块调试从模式和主模式经历

Zadig v1.13.0 believes in the power of openness, and workflow connects all values

GMT安装与使用

Yan Ji lost Beijing again, and more than half of the stores in the country were closed

Developing NES games with C language (cc65) 09, scrolling
随机推荐
Sub database and sub table may not be suitable for your system. Let's talk about how to choose sub database and sub table and newsql
1331. 数组序号转换 : 简单模拟题
If you don't roll the golden nine and silver ten, it's too late
界面控件Telerik UI for WPF - 如何使用RadSpreadsheet记录或评论
新零售电商O2O模式解析
Developing NES games with C language (cc65) 10. Game cycle
Hongjiu fruit passed the hearing: five month operating profit of 900million Ali and China agricultural reclamation are shareholders
[try to hack] intranet Foundation
New Oriental's single quarter revenue was 524million US dollars, a year-on-year decrease of 56.8%, and 925 learning centers were reduced
leetcode:数组
Brief discussion on open source OS distribution
Yan Ji lost Beijing again, and more than half of the stores in the country were closed
Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held
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
Open source database innovation in the era of digital economy | the 2022 open atom global open source summit database sub forum was successfully held
Exploration on cache design optimization of community like business
Use json.stringify() to format data
SQL injection less26 (filter spaces and comments, and use error injection without spaces)
Open source office (ospo) unveils Secrets