virtual ParseResultBase* Parse(const char* json, size_t length) const {
        VinenthzParseResult* pr = new VinenthzParseResult;

        json_config config;
        memset(&config, 0, sizeof(json_config));
        config.max_nesting = 0;
        config.max_data = 0;
        config.allow_c_comments = 0;
        config.allow_yaml_comments = 0;

        json_parser parser;
        json_parser_dom dom;
        json_parser_dom_init(&dom, tree_create_structure, tree_create_data, tree_append);
        json_parser_init(&parser, &config, json_parser_dom_callback, &dom);
        uint32_t processed;
        if (!json_parser_string(&parser, json, (uint32_t)length, &processed))
            pr->root = (json_val_t*)dom.root_structure;
        else {
            delete pr;
            pr = 0;
        }
        json_parser_free(&parser);
        json_parser_dom_free(&dom);
        return pr;
    }
예제 #2
0
xmmsv_t *
xmmsv_from_json (const char *spec)
{
	json_config conf = {
		0, /* buffer_initial_size (0=default) */
		0, /* max_nesting (0=no limit) */
		0, /* max_data (0=no limit) */
		1, /* allow_c_comments */
		0, /* allow_yaml_comments */
		NULL, /* user_calloc */
		NULL /* user_realloc */
	};
	json_parser_dom dom;
	json_parser parser;
	xmmsv_t *value;
	int error;

	json_parser_dom_init (&dom,
						  (json_parser_dom_create_structure) create_structure,
						  (json_parser_dom_create_data) create_data,
						  (json_parser_dom_append) append);
	json_parser_init (&parser, &conf, json_parser_dom_callback, &dom);

	error = json_parser_string (&parser, spec, strlen (spec), NULL);
	if (error != 0) {
		switch (error) {
			case JSON_ERROR_BAD_CHAR:
				fprintf (stderr, "Failed to parse due to bad character!\n");
				break;
			case JSON_ERROR_UNEXPECTED_CHAR:
				fprintf (stderr, "Failed to parse due to unexpected character!\n");
				break;
			case JSON_ERROR_NO_MEMORY:
				fprintf (stderr, "Failed to parse (%d)!\n", error);
				break;
		}

		return NULL;
	}

	assert (dom.root_structure != NULL);
	assert (dom.stack_offset == 0);

	value = (xmmsv_t *) dom.root_structure;

	json_parser_dom_free (&dom);
	json_parser_free (&parser);

	return value;
}
예제 #3
0
jobj * jobj_parse(const char * json_str)
{
	int res;
	jobj * o = NULL;
	json_parser_dom dom;
	json_parser p;
	json_config config;

	memset(&config, 0, sizeof(json_config));

	res = json_parser_dom_init(&dom, dom_mknode, dom_mkval, dom_append);
	if(res) return NULL;
	res = json_parser_init(&p, &config, json_parser_dom_callback, &dom);
	if(res) return NULL;

	res = json_parser_string(&p, json_str, strlen(json_str), NULL);
	if(!res && json_parser_is_done(&p)) o = dom.root_structure;
	
	json_parser_free(&p);
	json_parser_dom_free(&dom);
	return o;	
}