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 960 B

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