diff options
author | Patrick Simianer <p@simianer.de> | 2014-07-13 14:04:45 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-07-13 14:04:45 +0200 |
commit | 625269764ebbe8d0b566e6ef5fc26a6bccd4181d (patch) | |
tree | 70c54cb1dae9afddaefd7f0824427e95dd688081 /test_gason.cc |
init
Diffstat (limited to 'test_gason.cc')
-rw-r--r-- | test_gason.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test_gason.cc b/test_gason.cc new file mode 100644 index 0000000..d78c385 --- /dev/null +++ b/test_gason.cc @@ -0,0 +1,71 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <string.h> + +/* + * 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<char>(ifs)), + (istreambuf_iterator<char>())); + + char* s = strdup(json_str.c_str()); + char *p; + JsonValue v; + JsonAllocator a; + JsonParseStatus status = jsonParse(s, &p, &v, a); + walk(v); + + return 0; +} + |