所以我使用的是jansson
库,我想设置一个值:
json_object_set_new(event," error_code",json_integer(response-> error_code));
问题在于,我需要free
response
struct,但仍然使用我在json_object_set_new
中设置的值。
我应该从response->error_code
复制值吗?我该怎么做?
某些背景信息:
plugin_response: {
if(!response->message && response->error_code == 0) {
response->error_code = JANUS_AUDIOBRIDGE_ERROR_UNKNOWN_ERROR;
if(response->error_cause == NULL) {
response->error_cause = g_strdup_printf("%s", "Invalid response");
}
}
json_t *event = json_object();
if(!response->message && response->error_code != 0) {
/* Prepare JSON error event */
json_object_set_new(event, "audiobridge", json_string("event"));
json_object_set_new(event, "error_code", json_integer(response->error_code));
json_object_set_new(event, "error", json_string(response->error_cause));
} else {
event = json_deep_copy(response->message);
}
if(root != NULL)
json_decref(root);
if(jsep != NULL)
json_decref(jsep);
g_free(transaction);
g_free(response);
return janus_plugin_result_new(JANUS_PLUGIN_OK, NULL, event);
}
编辑:我也在使用GLib,所以如果有一个漂亮的方法,我都是耳朵。