You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_object_iterator.c 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifdef NDEBUG
  2. #undef NDEBUG
  3. #endif
  4. #include "config.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "json_object.h"
  9. #include "json_object_iterator.h"
  10. #include "json_tokener.h"
  11. int main(int atgc, char **argv)
  12. {
  13. const char *input = "{\n\
  14. \"string_of_digits\": \"123\",\n\
  15. \"regular_number\": 222,\n\
  16. \"decimal_number\": 99.55,\n\
  17. \"boolean_true\": true,\n\
  18. \"boolean_false\": false,\n\
  19. \"big_number\": 2147483649,\n\
  20. \"a_null\": null,\n\
  21. }";
  22. struct json_object *new_obj;
  23. struct json_object_iterator it;
  24. struct json_object_iterator itEnd;
  25. it = json_object_iter_init_default();
  26. new_obj = json_tokener_parse(input);
  27. it = json_object_iter_begin(new_obj);
  28. itEnd = json_object_iter_end(new_obj);
  29. while (!json_object_iter_equal(&it, &itEnd))
  30. {
  31. printf("%s\n", json_object_iter_peek_name(&it));
  32. printf("%s\n", json_object_to_json_string(json_object_iter_peek_value(&it)));
  33. json_object_iter_next(&it);
  34. }
  35. json_object_put(new_obj);
  36. return 0;
  37. }