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.

json_visit.h 3.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _json_c_json_visit_h_
  2. #define _json_c_json_visit_h_
  3. #include "json_object.h"
  4. typedef int (json_c_visit_userfunc)(json_object *jso, int flags,
  5. json_object *parent_jso, const char *jso_key,
  6. size_t *jso_index, void *userarg);
  7. /**
  8. * Visit each object in the JSON hierarchy starting at jso.
  9. * For each object, userfunc is called, passing the object and userarg.
  10. * If the object has a parent (i.e. anything other than jso itself)
  11. * its parent will be passed as parent_jso, and either jso_key or jso_index
  12. * will be set, depending on whether the parent is an object or an array.
  13. *
  14. * Nodes will be visited depth first, but containers (arrays and objects)
  15. * will be visited twice, the second time with JSON_C_VISIT_SECOND set in
  16. * flags.
  17. *
  18. * userfunc must return one of the defined return values, to indicate
  19. * whether and how to continue visiting nodes, or one of various ways to stop.
  20. *
  21. * Returns 0 if nodes were visited successfully, even if some were
  22. * intentionally skipped due to what userfunc returned.
  23. * Returns <0 if an error occurred during iteration, including if
  24. * userfunc returned JSON_C_VISIT_RETURN_ERROR.
  25. */
  26. int json_c_visit(json_object *jso, int future_flags,
  27. json_c_visit_userfunc userfunc, void *userarg);
  28. /**
  29. * Passed to json_c_visit_userfunc as one of the flags values to indicate
  30. * that this is the second time a container (array or object) is being
  31. * called, after all of it's members have been iterated over.
  32. */
  33. #define JSON_C_VISIT_SECOND 0x02
  34. /**
  35. * This json_c_visit_userfunc return value indicates that iteration
  36. * should proceed normally.
  37. */
  38. #define JSON_C_VISIT_RETURN_CONTINUE 0
  39. /**
  40. * This json_c_visit_userfunc return value indicates that iteration
  41. * over the members of the current object should be skipped.
  42. * If the current object isn't a container (array or object), this
  43. * is no different than JSON_C_VISIT_RETURN_CONTINUE.
  44. */
  45. #define JSON_C_VISIT_RETURN_SKIP 7547
  46. /**
  47. * This json_c_visit_userfunc return value indicates that iteration
  48. * of the fields/elements of the <b>containing</b> object should stop
  49. * and continue "popped up" a level of the object hierarchy.
  50. * For example, returning this when handling arg will result in
  51. * arg3 and any other fields being skipped. The next call to userfunc
  52. * will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc
  53. * call on "bar".
  54. * <pre>
  55. * {
  56. * "foo": {
  57. * "arg1": 1,
  58. * "arg2": 2,
  59. * "arg3": 3,
  60. * ...
  61. * },
  62. * "bar": {
  63. * ...
  64. * }
  65. * }
  66. * </pre>
  67. */
  68. #define JSON_C_VISIT_RETURN_POP 767
  69. /**
  70. * This json_c_visit_userfunc return value indicates that iteration
  71. * should stop immediately, and cause json_c_visit to return success.
  72. */
  73. #define JSON_C_VISIT_RETURN_STOP 7867
  74. /**
  75. * This json_c_visit_userfunc return value indicates that iteration
  76. * should stop immediately, and cause json_c_visit to return an error.
  77. */
  78. #define JSON_C_VISIT_RETURN_ERROR -1
  79. #endif /* _json_c_json_visit_h_ */