From 9a0859212de4d1304f9392fe910921227421c8c3 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 16 Aug 2014 21:25:52 +0100 Subject: cleanup --- src/test_gason.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/test_gason.cc (limited to 'src/test_gason.cc') diff --git a/src/test_gason.cc b/src/test_gason.cc new file mode 100644 index 0000000..d78c385 --- /dev/null +++ b/src/test_gason.cc @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +/* + * https://github.com/vivkin/gason + * + */ +#include "gason/gason.h" + +using namespace std; + + +void +print(const char *s) +{ + string u(s); + u = u.substr(1, 4); + if (u == "Goal") { + cerr << u << endl; + } +} + +void +walk(JsonValue o) +{ + switch (o.getTag()) { + case JSON_TAG_NUMBER: + break; + case JSON_TAG_BOOL: + break; + case JSON_TAG_STRING: + print(o.toString()); + break; + case JSON_TAG_ARRAY: + if (!o.toNode()) + break; + for (auto i : o) + walk(i->value); + break; + case JSON_TAG_OBJECT: + if (!o.toNode()) + break; + for (auto i : o) { + print(i->key); + walk(i->value); + } + break; + case JSON_TAG_NULL: + break; + } +} + +int +main(int argc, char** argv) +{ + ifstream ifs(argv[1]); + string json_str((istreambuf_iterator(ifs)), + (istreambuf_iterator())); + + char* s = strdup(json_str.c_str()); + char *p; + JsonValue v; + JsonAllocator a; + JsonParseStatus status = jsonParse(s, &p, &v, a); + walk(v); + + return 0; +} + -- cgit v1.2.3