• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

json-parser/json-builder: The serializing counterpart to json-parser.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

json-parser/json-builder

开源软件地址:

https://github.com/json-parser/json-builder

开源编程语言:

C 98.7%

开源软件介绍:

The serializing counterpart to json-parser.

As with json-parser: BSD licensed, almost ANSI C89 apart from a single use of snprintf.

Usage

Quick example (docs coming soon):

json_value * arr = json_array_new(0);
json_array_push(arr, json_string_new("Hello world!"));
json_array_push(arr, json_integer_new(128));

char * buf = malloc(json_measure(arr));
json_serialize(buf, arr);

printf("%s\n", buf);
[ "Hello world!", 128 ]

json-builder is fully interoperable with json-parser:

char json[] = "[ 1, 2, 3 ]";

json_settings settings = {};
settings.value_extra = json_builder_extra;  /* space for json-builder state */

char error[128];
json_value * arr = json_parse_ex(&settings, json, strlen(json), error);

/* Now serialize it again. */
char * buf = malloc(json_measure(arr));
json_serialize(buf, arr);

printf("%s\n", buf);
[ 1, 2, 3 ]

Note that values created by or modified by json-builder must be freed with json_builder_free instead of json_value_free, otherwise the memory of the builder state will be leaked.

Modes

  • json_serialize_mode_multiline — Generate multi-line JSON, for example:
[
  1,
  2,
  3
]
  • json_serialize_mode_single_line — Generate JSON on a single line, for example:
[ 1, 2, 3 ]
  • json_serialize_mode_packed — Generate JSON as tightly packed as possible, for example:
[1,2,3]

Options

  • json_serialize_opt_CRLF — use CR/LF (Windows) line endings

  • json_serialize_opt_pack_brackets — do not leave spaces around brackets (e.g. [ 1, 2 ] becomes [1, 2])

  • json_serialize_opt_no_space_after_comma — do not leave spaces after commas

  • json_serialize_opt_no_space_after_colon — do not leave spaces after colons (inside objects)

  • json_serialize_opt_use_tabs — indent using tabs instead of spaces when in multi-line mode

  • indent_size — the number of tabs or spaces to indent with in multi-line mode




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap