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

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