Json解析 - c语言库libJsonParser

项目zip包先放上来,大家可以下载编译以后运行(gif文件另存为zip即可)。

http://hi.csdn.net/attachment/201107/25/0_1311593791wkYN.gif


libJsonParser是JsonParser的dll项目,源代码来自json.org网站。

http://fara.cs.uni-potsdam.de/~jsg/json_parser/


testJsonParser是原作者自带的main.c文件。

int main(int argc, char* argv[]) {
	int count = 0, result = 0;
	FILE* input;

	JSON_config config;

	struct JSON_parser_struct* jc = NULL;

	init_JSON_config(&config);

	config.depth                  = 19;
	config.callback               = &print;
	config.allow_comments         = 1;
	config.handle_floats_manually = 0;

	/* Important! Set locale before parser is created.*/
	if (argc >= 2) {
		if (!setlocale(LC_ALL, argv[1])) {
			fprintf(stderr, "Failed to set locale to '%s'\n", argv[1]);
		}
	} else {
		fprintf(stderr, "No locale provided, C locale is used\n");
	}

	jc = new_JSON_parser(&config);

	input = stdin;
	for (; input ; ++count) {
		int next_char = fgetc(input);
		if (next_char <= 0) {
			break;
		}
		if (!JSON_parser_char(jc, next_char)) {
			fprintf(stderr, "JSON_parser_char: syntax error, byte %d\n", count);
			result = 1;
			goto done;
		}
	}
	if (!JSON_parser_done(jc)) {
		fprintf(stderr, "JSON_parser_end: syntax error\n");
		result = 1;
		goto done;
	}

done:
	delete_JSON_parser(jc);
	return result;
}



release目录下有编译好的dll,和测试命令行。下图是测试结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值