Microchip
直播中

胡楚翘

7年用户 218经验值
私信 关注
[问答]

怎么支持PIC32中的JSON解析和序列化

我正在寻找支持或库,允许我将JSON对象序列化为char数组,并将char数组/字符串解析为JSON对象。我查看了JSMN库,但它看起来只是解析,而不是序列化。我目前在ARDUINO板上使用ARDuijJon来执行这些任务,我想将代码迁移到PIC32。我正在寻找尽可能接近的功能,以便于迁移。我是:1。使用ARDIONJSON 2创建内存中的JSON对象。将所有需要传输的数据复制到新创建的JSON对象。3。调用ARDUIONJSON函数将新创建的JSON对象序列化为char数组。4。通过UART 5发送字符阵列。销毁JSON对象(超出范围),并在接收序列化字符串时:1。在内存中创建一个JSON对象并使用ARDuijJSON解析函数填充它。2。将所有相关数据从新创建的JSON对象复制到我自己的数据结构。3。销毁JSON对象(走出范围)。就像我说的,我正在寻找一个类似于这个功能的库,再加上UART/串行通信。我会感激任何建议,就是这样的东西存在。提前感谢。

以上来自于百度翻译


      以下为原文

     
I am looking for support or libraries to allow me to serialize a JSON object into a char array and to parse a char array/string into a JSON object. I looked into the jsmn library but it looks like it only does parsing, not serializing.

I am currently using ArduinoJson on an Arduino board to perform those tasks and I would like to migrate the code to a PIC32. I am looking for as close a functionality as possible for ease of migration.

I am:

1. Creating a JSON object in memory, using ArduinoJson.
2. Copying all the data I need to transmit into the newly created JSON object.
3. Calling an ArduinoJson function to serialize the newly created JSON object into a char array.
4. Transmitting the char array through UART.
5. Destroying the JSON object (going out of scope).

And when receiving a serialized string:

1. Create a JSON object in memory and populate it using ArduinoJson parse function.
2. Copy all relevant data from the newly created JSON object to my own data structures.
3. Destroy the JSON object (going out of scope).

Like I said, I am looking for a library that will closely resemble this functionality, coupled with UART/Serial communication. I will appreciate any suggestions, is such a thing exists. Thanks in advance.

回帖(19)

陆欣楠

2018-11-28 17:00:35
你看过DaveGamble在吉瑟布上的CJSON吗?我认为这是一种比较流行的实现方式。

以上来自于百度翻译


      以下为原文

    Have you looked at cJSON by DaveGamble on GitHub?  I think this is one of the more popular implementations.
举报

冯伟

2018-11-28 17:18:47
谢谢。我仔细看了看,看起来很有希望。我会深入研究的。

以上来自于百度翻译


      以下为原文

    jg_ee
 
Thanks. I looked into it a bit and it looks promising. I will look further into it.
举报

王淑英

2018-11-28 17:26:40
我已经使用了这两个库。CJSON有一个更好的接口,并生成和解析JSON。不幸的是,该库使用了大量的分配/免费语句,因此RAM内存使用率相当高且不可预测。JSMN仅解析并具有较差的接口,但它使RAM使用最小化,只使用静态存储器。使用SaveTF生成JSON相对容易。如果您有很多内存,CJSON是一个不错的选择。

以上来自于百度翻译


      以下为原文

    I have used both libraries.
 
cJSON has a much better interface, and generates as well as parses the JSON.  Unfortunately the library uses a lot of allocate/free statements, so RAM memory usage is fairly high and unpredictable.
 
jsmn only parses and has a poorer interface, but it minimizes the RAM usage and only uses static memory.  Generating JSON is relatively easy using sprintf. 
 
If you have a lot of memory cJSON is a good choice.
举报

李天竹

2018-11-28 17:37:18
您是否尝试直接传输数据,而不浪费您的时间和MCU资源将数据转换为JSON?

以上来自于百度翻译


      以下为原文

    Have you tried transmitting data directly, without wasting your time and MCU resources on converting the data to and from JSON?
举报

更多回帖

发帖
×
20
完善资料,
赚取积分