int main() { printf("Test Function\n"); //dup_init(); iot_init(); //rule_init(); json_object *jso = json_object_from_file("./example/iot_config.json"); if (jso) { //json_object_put(jso); json_object_object_foreach(jso, key, child_object) { if(!strcmp(key, "iot-device")) { for(int i =0; i < json_object_array_length(child_object); i++) { json_object* iot_object = json_object_array_get_idx(child_object, i); iot_json_create(iot_object); printf("\n"); } } else if(!strcmp(key, "rule")) { for(int i =0; i < json_object_array_length(child_object); i++) { json_object* rule_object = json_object_array_get_idx(child_object, i); rule_json_create(rule_object); printf("\n"); } } } } return 0; }
iot_json_t *iot_json_add_array(iot_json_t *o, const char *key, iot_json_type_t type, ...) { va_list ap; void *arr; ssize_t cnt, i; iot_json_t *a; va_start(ap, type); arr = va_arg(ap, void *); cnt = va_arg(ap, ssize_t); a = iot_json_create(IOT_JSON_ARRAY); if (a == NULL) goto fail; switch (type) { case IOT_JSON_STRING: for (i = 0; i < cnt || (cnt < 0 && ((char **)arr)[i]); i++) { if (!iot_json_array_append_string(a, ((char **)arr)[i])) goto fail; } break; case IOT_JSON_INTEGER: for (i = 0; i < cnt; i++) { if (!iot_json_array_append_integer(a, ((int *)arr)[i])) goto fail; } break; case IOT_JSON_DOUBLE: for (i = 0; i < cnt; i++) { if (!iot_json_array_append_double(a, ((double *)arr)[i])) goto fail; } break; case IOT_JSON_BOOLEAN: for (i = 0; i < cnt; i++) { if (!iot_json_array_append_boolean(a, ((bool *)arr)[i])) goto fail; } break; default: goto fail; } va_end(ap); iot_json_add(o, key, a); return a; fail: va_end(ap); iot_json_unref(a); return NULL; }