| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // json_test.cpp
- // json
- //
- // Created by Sam Jaffe on 4/22/16.
- //
- #include "json_binder.hpp"
- #include <fstream>
- struct test_t {
- int a, b;
- };
- struct test_2_t {
- test_t t;
- double d;
- };
- int main(int argc, char const** argv) {
- auto bind1 = json::binder::object_binder<test_t>{}
- ("a", &test_t::a)
- ("b", &test_t::b);
-
- json::binder::tuple_binder<test_t>{}
- (&test_t::a)
- (&test_t::b);
-
- auto bind2 = json::binder::object_binder<test_2_t>{}
- ("t", &test_2_t::t, bind1)("d", &test_2_t::d);
-
- {
- test_t out{};
- std::string data = "{\"a\":1,\"b\":2,\"c\":3}";
-
- json::parser::parse(json::binder::bind(out, bind1), data);
- std::cout << out.a << ',' << out.b << std::endl;
- }
- {
- test_2_t out{};
- std::string data = "{\"t\":{\"a\":1,\"b\":2},\"d\":1.5}";
- std::cout << data << std::endl;
- std::ifstream file("/Users/samjaffe/Documents/Programming/XTools/misc/json/example.json");
- json::parser::parse(json::binder::bind(out, bind2), file);
- std::cout << '{' << out.t.a << ',' << out.t.b << "}," << out.d << std::endl;
-
- std::string sout;
- json::parser::write(json::binder::bind(out, bind2), sout);
- std::cout << sout << std::endl;
- }
-
- }
|