0

When I use json-c 0.9 to parse cstr to json object, I found that if json_tokener_parse failed, the return address of json_object is the errcode

struct json_object* json_tokener_parse(const char *str){
    struct json_tokener* tok;
    struct json_object* obj;

    tok = json_tokener_new();
    obj = json_tokener_parse_ex(tok, str, -1);
    if(tok->err != json_tokener_success)
        obj = (struct json_object*)error_ptr(-tok->err);
    json_tokener_free(tok);
    return obj;
}

this is the code in json-c0.9 It's a bug? What should I check if it's failed?

leo
  • 361
  • 1
  • 5
  • 11
  • 1
    Your code above for extracting the error message looks bogus, but it's hard to say without the specs. – Hot Licks Nov 29 '13 at 04:00

1 Answers1

0

Mentioned below is the code that i used to convert C structure to JSON object for your reference:

    void fill_json_object(st_service *data) {
    st_service *data2;
    json_object *jrecord_id;
    json_object *jservice;
    jobj = json_object_new_object();
    data2 = (st_request_web_service *) data;

    jrecord_id = json_object_new_int(data2->i_rec_id);
    jservice = json_object_new_int(data2->i_service_id);

    json_object_object_add(jobj, "record_id", jrecord_id);
    json_object_object_add(jobj, "service", jservice);

    return;
}
Technext
  • 7,887
  • 9
  • 48
  • 76