JSON解析在ANSI C [英] Parse JSON in ANSI C

查看:327
本文介绍了JSON解析在ANSI C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读JSON-CN codeD数据转换成C结构。 JSON数据结构提前,相对平坦是已知的,通过一些C结构的typedef模仿。在第三级左右的数组包含有在一次只处理一个JSON对象的一个​​极其漫长的名单。

I'd like to read JSON-encoded data into C structs. The structure of the json data is known in advance, relatively flat and mimicked by some C struct typedefs. An array at the third level or so contains an extremely lengthy list of JSON objects which have to be processed one at a time.

在code是为了一个非常约束系统上运行,以便图书馆不应该动态分配内存。

The code is intended to run on a very constrained system so the library should not dynamically allocate memory.

我知道有 JSON库Crockford的列表,但我不能肯定哪一个是最适合规定的问题。

I know there is Crockford's List of JSON libraries, but I'm not quite sure which one is the best fit for the stated problem.

推荐答案

尝试 jsmn lib下,我喜欢它可以解析任何JSON文件只有两个的malloc的。

Try jsmn lib, I love that it can parse any json file with only two malloc's.

jsmn是解析JSON数据格式的简约库。它可以在小项目可以容易地使用,或者可以集成到嵌入式系统。

jsmn is a minimalistic library for parsing JSON data format. It can be easily used in small projects or can be integrated into embedded systems.

jsmn是一个不错的选择,怎么一回事,因为:结果
   - 它是与C98结果,兼容
   - 它不使用动态内存分配结果
   - 它具有可能的最小开销结果
   - 它仅需要一个传球解析JSON数据结果
   - 它没有依赖性,甚至libc的结果
   - 它是在MIT许可下发布的,因此你可以在你的专有项目中使用

jsmn is a good choice, beacuse:
- it is compatible with C98
- it uses no dynamic memory allocation
- it has the smallest possible overhead
- it needs only one pass to parse JSON data
- it has no dependencies, even libc
- it is distributed under MIT license, so you can use it in your proprietary projects

这篇关于JSON解析在ANSI C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆