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,和测试命令行。下图是测试结果:

Json解析 - c语言库libJsonParser_第1张图片

你可能感兴趣的:(Json解析 - c语言库libJsonParser)