当前位置:网站首页>Solution: STM32 failed to parse data using cjson
Solution: STM32 failed to parse data using cjson
2022-06-30 17:26:00 【Leung_ ManWah】
One 、 problem
stay STM32 transplant cJSON Behind the library , Use cJSON_Parse(), Parse failure .
char cmd[512] = "{\"msg\":\"this is successful start up\",\"result\":1,\"action\":\"req_startUp\",\"responseData\":\"trustedDevice\",\"serial_no\":\"0341\",\"timestamp\":1656489886238}";
cJSON *pRoot = cJSON_Parse(cmd);
const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL)
{
printf("Error before: %s\n", error_ptr);
}
Use cJSON_GetErrorPtr() The following errors were analyzed :
Error before: ,"timestamp":1656489886238}
And when you remove serial_no Field after , Can be parsed successfully .
char cmd[512] = "{\"msg\":\"this is successful start up\",\"result\":1,\"action\":\"req_startUp\",\"responseData\":\"trustedDevice\",\"timestamp\":1656489886238}";
Two 、 reason
When the parsed data is long , Will parse failure , But short data is no problem , The later investigation is because cJSON Parsing requires a large amount of memory , Overflow causes parsing to fail .
see STM32 Startup file . Such as startup_stm32f407xx.s, Find out :
- The stack area (stack): Automatically allocated and released by the compiler , Stores the parameter values of the function 、 The value of a local variable, etc , It operates like a stack in a data structure .
- Heap area (heap): Usually assigned and released by programmers , If programmers don't release , It may be recycled by the operating system at the end of the program . The allocation is similar to the linked list in the data structure .
** Be careful :** Remember to cJSON_Delete Delete object , also cJSON_Print Will keep applying for memory , After all calls, be sure to free Release , Otherwise, memory overflow will occur after multiple calls . Lead to the following cJSON_Print Can not apply for memory .
3、 ... and 、 resolvent
After increasing space , Problem solving 
• from Leung Written in 2022 year 6 month 30 Japan
• Reference resources :STM32 Engineering use cjson The reason why the library failed to parse data
边栏推荐
- Parker proportional overflow valve rs10r35s4sn1jw
- ssh工具 pyqt
- 泰山OFFICE技术讲座:同一行不同字号的字如何对齐绘制
- Map集合
- Share 5 commonly used feature selection methods, and you must see them when you get started with machine learning!!!
- Ningx 1.20.2
- Supplementary
- AcWing 第 57 场周赛
- k线图快速入门必读
- NielsenIQ迎来零售实验室负责人Dawn E. Norvell,将加速扩张全球零售战略
猜你喜欢

Canvas mouse control gravity JS effect
![[零基础学IoT Pwn] 环境搭建](/img/3b/a0689a1570fcc40bb9a5a4e9cdc63c.png)
[零基础学IoT Pwn] 环境搭建

Interview shock 60: what will cause MySQL index invalidation?

知名互联网房屋租赁服务公司物联网关键业务迁移上云实践

3D图表有效提升数据大屏档次

Nouvelle version de shangdingyun | la fonction favorite est en ligne pour répondre aux besoins d'utilisation personnelle

Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies

送受伤婴儿紧急就医,滴滴司机连闯五个红灯

3D chart effectively improves the level of large data screen

nodejs学习笔记二
随机推荐
中基协:推荐使用电子合同
leetcode:1042. Do not plant flowers adjacent to each other [randomly fill in qualified + no contradiction will be formed behind + set.pop]
开发那些事儿:如何在视频中添加文字水印?
理解现货白银走势的关键
[untitled] write a student achievement and information management system in C language to realize the operation interface, clear screen display of current operation functions, reading and inputting st
canvas云朵形状动画
Canvas mouse control gravity JS effect
Cesium-1.72 learning (China national boundary)
Rexroth hydraulic control check valve z2s10-1-3x/
Required plug-ins for idea
[C language] explain threads in detail - solve the problem of shared memory caused by concurrent programs by "locking"
Consolidate entry-C basic variables and constants
List becomes vector list becomes vector list vector
每日刷题记录 (九)
【C语言】详解线程 — 开启两个线程
In the past, the industrial Internet we knew only appeared as a substitute for the consumer Internet
ssh工具 pyqt
flutter 音乐 录音 播放 audioplayers
24: Chapter 3: develop pass service: 7: user defined exceptions (to represent errors in the program); Create graceexceptionhandler to handle exceptions globally and uniformly (build JSON data of corre
美国穆格moog伺服阀D661-4577C