json-glib problem



I want to us json-glib to parse a json file ,and I wrote a demo like this.
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
int main(int argc,char **argv)
    {
        JsonParser *parser;
        GError *error;
        g_type_init();
        parser = json_parser_new();
        json_parser_load_from_file(parser,"info.json",&error);
        if(error)
            {
                g_print("error is %s\n",error->message);
                g_error_free(error);
                g_object_unref(parser);
                return EXIT_FAILURE;
            }
        JsonNode *root;
        root = json_parser_get_root(parser);
        if(JSON_NODE_HOLDS_ARRAY(root))
            {
                puts("hold array\n");
                JsonArray *array;
                array = json_node_get_array(root);
                g_print("the length of the array is %d\n",json_array_get_length(array));
                root = json_array_get_element(array,0);
                if(JSON_NODE_HOLDS_OBJECT(root))
                    {
                        JsonObject *newobj;
                        newobj = json_node_get_object(root);
                    }
        return EXIT_SUCCESS;
            }
    }

and the info.json file is here.
[{"tinyurl":"http://hdn.xnimg.cn/photos/hdn121/20121221/2320/tiny_9gJc_310d000027911375.jpg","sex":1,"university_history":[{"department":"others","name":"University of Alaska Fairbanks","year":2008}],"work_history":[],"star":0,"mainurl":"http://hdn.xnimg.cn/photos/hdn521/20121221/2320/h_main_Rka5_5af7000023451376.jpg","headurl":"http://hdn.xnimg.cn/photos/hdn521/20121221/2320/h_head_uFt9_5af7000023451376.jpg","vip":4,"hometown_location":{"province":"黑龙江","city":"shuangyashang"},"name":"xiaolongfeng","email_hash":"","zidou":1}]


but when I compile the demo,I got a segment fault,I do not know what`s wrong with my demo program.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]