#include <stdio.h>
#include "json.h"
#include "protocol.jdr.h"
#include <string.h>

static struct json_object* load_file(const char* file)
{
	FILE* fin;
	json_object *obj = NULL;
	struct json_tokener* tok = NULL;
	enum json_tokener_error jerr;
	int lineno = 0;

	fin = fopen(file, "r");
	tok= json_tokener_new();
	while(!feof(fin))
	{
		char buff[4096];//超过4096显示行号会有问题
		size_t buff_size;
		fgets(buff, sizeof(buff), fin);
		++lineno;
		buff_size = strlen(buff);
		obj = json_tokener_parse_ex(tok, buff, (int)buff_size);
		jerr = json_tokener_get_error(tok);
		if(jerr != json_tokener_continue)
		{
			break;
		}
	};
	json_tokener_free(tok);
	fclose(fin);

	if (jerr != json_tokener_success)
	{
		fprintf(stderr, "%s,%d: Error: %s\n", "etc/tconnd.json", lineno, json_tokener_error_desc(jerr));
		goto done;
	}

done:
	return obj;
}

int main()
{
	json_object *obj = NULL;
	obj = load_file("example.json");
	if(obj != NULL)
	{
		json_object_put(obj);
	}

	return 0;
}

