JSMN
====
[![Build Status](https://travis-ci.org/zserge/jsmn.svg?branch=master)](https://travis-ci.org/zserge/jsmn)
jsmn (pronounced like 'jasmine') is a minimalistic JSON parser in C. It can be
easily integrated into resource-limited or embedded projects.
You can find more information about JSON format at [json.org][1]
Library sources are available at https://github.com/zserge/jsmn
The web page with some information about jsmn can be found at
[http://zserge.com/jsmn.html][2]
Philosophy
----------
Most JSON parsers offer you a bunch of functions to load JSON data, parse it
and extract any value by its name. jsmn proves that checking the correctness of
every JSON packet or allocating temporary objects to store parsed JSON fields
often is an overkill.
JSON format itself is extremely simple, so why should we complicate it?
jsmn is designed to be **robust** (it should work fine even with erroneous
data), **fast** (it should parse data on the fly), **portable** (no superfluous
dependencies or non-standard C extensions). And of course, **simplicity** is a
key feature - simple code style, simple algorithm, simple integration into
other projects.
Features
--------
* compatible with C89
* no dependencies (even libc!)
* highly portable (tested on x86/amd64, ARM, AVR)
* about 200 lines of code
* extremely small code footprint
* API contains only 2 functions
* no dynamic memory allocation
* incremental single-pass parsing
* library code is covered with unit-tests
Design
------
The rudimentary jsmn object is a **token**. Let's consider a JSON string:
'{ "name" : "Jack", "age" : 27 }'
It holds the following tokens:
* Object: `{ "name" : "Jack", "age" : 27}` (the whole object)
* Strings: `"name"`, `"Jack"`, `"age"` (keys and some values)
* Number: `27`
In jsmn, tokens do not hold any data, but point to token boundaries in JSON
string instead. In the example above jsmn will create tokens like: Object
[0..31], String [3..7], String [12..16], String [20..23], Number [27..29].
Every jsmn token has a type, which indicates the type of corresponding JSON
token. jsmn supports the following token types:
* Object - a container of key-value pairs, e.g.:
`{ "foo":"bar", "x":0.3 }`
* Array - a sequence of values, e.g.:
`[ 1, 2, 3 ]`
* String - a quoted sequence of chars, e.g.: `"foo"`
* Primitive - a number, a boolean (`true`, `false`) or `null`
Besides start/end positions, jsmn tokens for complex types (like arrays
or objects) also contain a number of child items, so you can easily follow
object hierarchy.
This approach provides enough information for parsing any JSON data and makes
it possible to use zero-copy techniques.
Usage
-----
Download `jsmn.h`, include it, done.
```
#include "jsmn.h"
...
jsmn_parser p;
jsmntok_t t[128]; /* We expect no more than 128 JSON tokens */
jsmn_init(&p);
r = jsmn_parse(&p, s, strlen(s), t, 128);
```
Since jsmn is a single-header, header-only library, for more complex use cases
you might need to define additional macros. `#define JSMN_STATIC` hides all
jsmn API symbols by making them static. Also, if you want to include `jsmn.h`
from multiple C files, to avoid duplication of symbols you may define `JSMN_HEADER` macro.
```
/* In every .c file that uses jsmn include only declarations: */
#define JSMN_HEADER
#include "jsmn.h"
/* Additionally, create one jsmn.c file for jsmn implementation: */
#include "jsmn.h"
```
API
---
Token types are described by `jsmntype_t`:
typedef enum {
JSMN_UNDEFINED = 0,
JSMN_OBJECT = 1,
JSMN_ARRAY = 2,
JSMN_STRING = 3,
JSMN_PRIMITIVE = 4
} jsmntype_t;
**Note:** Unlike JSON data types, primitive tokens are not divided into
numbers, booleans and null, because one can easily tell the type using the
first character:
* <code>'t', 'f'</code> - boolean
* <code>'n'</code> - null
* <code>'-', '0'..'9'</code> - number
Token is an object of `jsmntok_t` type:
typedef struct {
jsmntype_t type; // Token type
int start; // Token start position
int end; // Token end position
int size; // Number of child (nested) tokens
} jsmntok_t;
**Note:** string tokens point to the first character after
the opening quote and the previous symbol before final quote. This was made
to simplify string extraction from JSON data.
All job is done by `jsmn_parser` object. You can initialize a new parser using:
jsmn_parser parser;
jsmntok_t tokens[10];
jsmn_init(&parser);
// js - pointer to JSON string
// tokens - an array of tokens available
// 10 - number of tokens available
jsmn_parse(&parser, js, strlen(js), tokens, 10);
This will create a parser, and then it tries to parse up to 10 JSON tokens from
the `js` string.
A non-negative return value of `jsmn_parse` is the number of tokens actually
used by the parser.
Passing NULL instead of the tokens array would not store parsing results, but
instead the function will return the value of tokens needed to parse the given
string. This can be useful if you don't know yet how many tokens to allocate.
If something goes wrong, you will get an error. Error will be one of these:
* `JSMN_ERROR_INVAL` - bad token, JSON string is corrupted
* `JSMN_ERROR_NOMEM` - not enough tokens, JSON string is too large
* `JSMN_ERROR_PART` - JSON string is too short, expecting more JSON data
If you get `JSMN_ERROR_NOMEM`, you can re-allocate more tokens and call
`jsmn_parse` once more. If you read json data from the stream, you can
periodically call `jsmn_parse` and check if return value is `JSMN_ERROR_PART`.
You will get this error until you reach the end of JSON data.
Other info
----------
This software is distributed under [MIT license](http://www.opensource.org/licenses/mit-license.php),
so feel free to integrate it in your commercial products.
[1]: http://www.json.org/
[2]: http://zserge.com/jsmn.html
没有合适的资源?快使用搜索试试~ 我知道了~
Libredwg androidstudio交叉编译生成的动态库so
共228个文件
h:71个
txt:49个
c:40个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 175 浏览量
2023-09-08
10:07:00
上传
评论
收藏 38.94MB ZIP 举报
温馨提示
Libredwg的源码通过Android STudio交叉编译生成的库,下载下来就能直接用,省去了自己编译,修改报错,不兼容或者环境的问题。 arm64-v8a/ armeabi-v7a/ x86/ x86_64/ 如果你需要原始的可自己编译的工程可以私信找我,我免费发个你,
资源推荐
资源详情
资源评论
收起资源包目录
Libredwg androidstudio交叉编译生成的动态库so (228个子文件)
dwg2dxf.1 1KB
dxfwrite.1 1KB
dwggrep.1 1KB
dwgwrite.1 1KB
dxf2dwg.1 1KB
dwgrewrite.1 1KB
dwgread.1 1KB
dwglayers.1 995B
dwg2SVG.1 892B
dwgbmp.1 842B
dwg2ps.1 816B
dwgfilter.1 742B
Makefile.am 5KB
Makefile.am 5KB
Makefile.am 3KB
dynapi.c 854KB
dwg_api.c 759KB
in_dxf.c 482KB
encode.c 270KB
decode.c 225KB
in_json.c 187KB
out_dxf.c 161KB
out_dxfb.c 118KB
out_json.c 108KB
bits.c 107KB
dwg.c 100KB
objects.c 97KB
decode_r2007.c 72KB
dwggrep.c 63KB
dxfclasses.c 62KB
free.c 57KB
classes.c 48KB
out_geojson.c 39KB
print.c 32KB
dwg2SVG.c 30KB
decode_r11.c 26KB
common.c 23KB
reedsolomon.c 16KB
dxfwrite.c 15KB
dwgwrite.c 14KB
codepages.c 13KB
dxf2dwg.c 13KB
tests.c 12KB
dwgrewrite.c 11KB
dwg2ps.c 11KB
dwg2dxf.c 11KB
dwgread.c 10KB
dwgbmp.c 8KB
dwglayers.c 6KB
hash.c 6KB
geom.c 5KB
escape.c 4KB
getopt.c 4KB
jsondump.c 3KB
simple.c 2KB
.clang-format 3KB
native-lib.cpp 537B
.git 29B
CP932.h 2.03MB
WINDOWS-949.h 1.87MB
CP949.h 1.87MB
WINDOWS-936.h 1.86MB
JOHAB.h 1.84MB
WINDOWS-950.h 1.6MB
WINDOWS-932.h 1.45MB
WINDOWS-1361.h 1.45MB
BIG5.h 1.42MB
GB2312.h 715KB
dwg_api.h 350KB
dwg.h 321KB
dec_macros.h 135KB
spec.h 67KB
common.h 24KB
bits.h 14KB
in_dxf.h 14KB
jsmn.h 12KB
CP852.h 10KB
CP860.h 10KB
CP861.h 10KB
CP865.h 10KB
CP437.h 10KB
CP866.h 10KB
CP863.h 10KB
CP850.h 10KB
CP864.h 9KB
CP857.h 9KB
CP855.h 9KB
logging.h 9KB
WINDOWS-1250.h 9KB
ISO-8859-2.h 9KB
ISO-8859-4.h 9KB
WINDOWS-1252.h 9KB
WINDOWS-1254.h 9KB
WINDOWS-1251.h 9KB
MACINTOSH.h 9KB
CP869.h 9KB
ISO-8859-9.h 9KB
ISO-8859-3.h 9KB
WINDOWS-1258.h 9KB
WINDOWS-1257.h 9KB
共 228 条
- 1
- 2
- 3
资源评论
前网易架构师-高司机
- 粉丝: 8104
- 资源: 202
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功