void json_print_list(stat_t status, uint8_t flags) { switch (flags) { case JSON_NO_PRINT: break; case JSON_OBJECT_FORMAT: { json_print_object(nv_body); break; } case JSON_RESPONSE_FORMAT: { json_print_response(status); break; } } }
static int Process_json(json_object *new_obj) { printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj)); printf("Result is %s\n", (new_obj == NULL) ? "NULL (error!)" : "not NULL"); if (!new_obj) return 1; // oops, we failed. json_print_object(new_obj);//遍历json对象的key和值 解析json数据 json_object_put(new_obj);/*释放资源*/ }
/* *打印JSON数据的值 *返回类型: none *返回值: none *传入参数json_object *类型 *author mleaf_hexi *mail:[email protected] */ static void json_print_value(json_object *obj) { char *action="CONFIG_DTS_DEVICE_OPTIONS"; char *configOption="CLOUD_PLATFORM_WEBSOCKET_URL"; if(!obj) return; json_type type=json_object_get_type(obj); if(type == json_type_boolean) { if(json_object_get_boolean(obj)) { printf("true"); } else { printf("false"); } } else if(type == json_type_double) { printf("json_object_get_double=%lf\n",json_object_get_double(obj)); } else if(type == json_type_int) { printf("json_object_get_int=%d\n",json_object_get_int(obj)); } else if(type == json_type_string) { if(strcmp(json_object_get_string(obj),action)==0) { printf("action checking out\n"); printf("action=%s\n",json_object_get_string(obj)); } else if(strcmp(json_object_get_string(obj),configOption)==0) { printf("configOption checking out\n"); printf("configOption=%s\n",json_object_get_string(obj)); } else { printf("json_object_get_string=%s\n",json_object_get_string(obj)); } } else if(type == json_type_object) { json_print_object(obj); } else if(type == json_type_array) { json_print_array(obj); } else { printf("ERROR"); } printf(" "); }
void json_print_value (json_object * obj) { if (!obj) return; json_type type = json_object_get_type (obj); if (type == json_type_boolean) { if (json_object_get_boolean (obj)) { printf ("true"); } else { printf ("false"); } } else if (type == json_type_double) { printf ("%lf", json_object_get_double (obj)); } else if (type == json_type_int) { printf ("%d", json_object_get_int (obj)); } else if (type == json_type_string) { printf ("%s", json_object_get_string (obj)); } else if (type == json_type_object) { json_print_object (obj); } else if (type == json_type_array) { json_print_array (obj); } else { printf ("ERROR"); } printf (" "); }