Skip to content
Snippets Groups Projects
Commit 9ce1011a authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[*] Fixed json_object list output now the amount of indentation is correct.

parent 13684a1f
No related branches found
No related tags found
2 merge requests!402Master 2809,!381Bugfix 12474
Pipeline #44439 passed with stage
in 17 minutes and 33 seconds
#include "dap_json_rpc_response.h"
#define LOG_TAG "dap_json_rpc_response"
#define INDENTATION_LEVEL " "
dap_json_rpc_response_t *dap_json_rpc_response_init()
{
......@@ -231,7 +232,7 @@ void json_print_object(json_object *obj, int indent_level) {
case json_type_object: {
json_object_object_foreach(obj, key, val) {
for (int i = 0; i <= indent_level; i++) {
printf(" "); // indentation level
printf(INDENTATION_LEVEL); // indentation level
}
printf("%s: ", key);
json_print_value(val, key, indent_level + 1, false);
......@@ -242,10 +243,13 @@ void json_print_object(json_object *obj, int indent_level) {
case json_type_array: {
int length = json_object_array_length(obj);
for (int i = 0; i < length; i++) {
for (int j = 0; j <= indent_level; j++) {
printf(INDENTATION_LEVEL); // indentation level
}
json_object *item = json_object_array_get_idx(obj, i);
json_print_value(item, NULL, indent_level + 1, length - 1 - i);
printf("\n");
}
printf("\n");
break;
}
default:
......@@ -349,24 +353,8 @@ int dap_json_rpc_response_printf_result(dap_json_rpc_response_t* response, char
switch(json_print_commands(cmd_name)) {
case 1: json_print_for_tx_history(response); break; return 0;
// case 2: json_print_for_mempool_list(response); break; return 0;
default: {
int json_type = 0;
json_object_is_type(response->result_json_object, json_type);
if (json_type == json_type_array) { /* print json array */
int result_count = json_object_array_length(response->result_json_object);
if (result_count <= 0) {
printf("response json array length is 0\n");
return -3;
}
for (int i = 0; i < result_count; i++) {
struct json_object * json_obj_result = json_object_array_get_idx(response->result_json_object, i);
json_print_object(json_obj_result, 0);
printf("\n");
json_object_put(json_obj_result);
}
} else { /* print json */
json_print_object(response->result_json_object, 0);
}
default: {/* print json */
json_print_object(response->result_json_object, 0);
}
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment