3982 views|4 replies

118

Posts

1

Resources
The OP
 

【EasyARM-RT1052 Review】 + cJSON transplantation and use [Copy link]

This post was last edited by ID.LODA on 2018-12-21 09:19 The use of JSON strings in IoT devices is also quite common nowadays. Let’s share and learn about it today. The cJSON library can be downloaded from the KEIL pack package. After downloading, I put it in the SDK_2.4.2_MIMXRT1052xxxxB\middleware directory. The open source protocols are all here, which is convenient for searching. Add the corresponding source files in the project and add the cJSON header file directory to the settings. CSJON will use dynamic memory allocation. You can use the management function you wrote in the previous section and initialize it as follows It is also okay not to set it, because the library has a default memory allocation function, which calls the compiler's malloc and free The following is a general JSON usage process, which initializes the memory allocation function, creates one or more JSON structures, adds strings or numbers or variables of different types, or sub-JSON variables, and then generates a JSON string. After using this string, release the JSON memory, otherwise it will always be occupied. With the previous memory management experiment, you can clearly see the memory usage and better understand the memory allocation mechanism of cJSON cJSON_Print generates the corresponding json array and you can see that it occupies memory separately, so you can release the corresponding root and child json memory and print the output The JSON parsing process is similar. First create a json variable, convert the data into a json structure, and then get the corresponding object json and take the value. Objectjson needs to correspond to the root cjson to read the value correctly. The following SystemCoreClock's object json belongs to child-json, but you will fail to get it from root-json. After the correct correspondence, you can get the value After calling the json array, you need to release it, otherwise it will accumulate calls for a long time and cause memory overflow The above is the generation and parsing of json, attach the project hello_eeworld.rar (148.9 KB, downloads: 12) , put it in the SDK_2.4.2_MIMXRT1052xxxxB\boards\EasyARM-RT1052-V1_0\demo_apps directory and unzip it. The keil version is V5.26.2.0 This content is originally created by EEWORLD forum user ID.LODA. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.




TIM图片20181220141512.png (23.55 KB, downloads: 0)

TIM图片20181220141512.png
This post is from NXP MCU

Latest reply

I have used cJosn, but it is not very friendly when the depth is large, and when there are many sub-json nesting  Details Published on 2018-12-21 11:16
 

1366

Posts

6

Resources
2
 
Thank you for sharing. Another question is, how much ROM and RAM does cJson occupy in the MCU?
This post is from NXP MCU

Comments

The library itself is not very large, but it requires a lot of memory when generating and parsing.  Details Published on 2018-12-21 11:01
 
Personal signature

1084534438 欢迎交流  [加油,一切皆有可能]

 
 

381

Posts

9

Resources
3
 
The library is very large, but it seems to be OK if you generate it yourself. I have tried it. . .
This post is from NXP MCU
 
 
 

118

Posts

1

Resources
4
 
This post was last edited by ID.LODA on 2018-12-21 11:02
RCSN posted on 2018-12-21 09:31 Thank you for sharing. Another question is, how much ROM and RAM does cJson occupy in the MCU?
The library itself is not very large, but it requires more memory when generating and parsing.
This post is from NXP MCU
 
 
 

295

Posts

1

Resources
5
 
I have used cJosn, but it is not very friendly when the depth is large, and when there are many sub-json nesting
This post is from NXP MCU
 
Personal signature

我的小站 我的博客

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list