From 1d379a5cf34475f66f2ab9359f77dac162c0a40e Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 6 Jun 2026 19:36:41 +1200 Subject: feat: JSON reading - Implemented a tokenizer for json - Implemented a method which will read json from a string using the tokenizer --- test/main.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'test/main.cpp') diff --git a/test/main.cpp b/test/main.cpp index 9430503..e86ec06 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -85,26 +86,29 @@ template <> std::string TehJSON::JSON::serializeData(std::shared_pt int main() { - TehJSON::JSON json; + TehJSON::JSON jsonWriter; // TestClass test1; // json["test1"].set(test1); - json["test_string"].set("stringy"); - json["test_int"].set(123); - json["test_float"].set(51.8); - json["test_object"]["test_int"].set(100); - json["test_object"]["test_float"].set(100); - - cout << json.getSerialized() << endl; - - // std::shared_ptr test; - // test = std::make_shared(1); - // test = std::make_shared(2); - // test = std::make_shared(std::string("test")); - // std::string& testRef = *(std::string*)test.get(); - // cout << *(std::string*)test.get() << endl; - // testRef += " test2"; - // cout << *(std::string*)test.get() << endl; - - - cout << "abc" << endl; + jsonWriter["test_string"].set("stringy"); + jsonWriter["test_int"].set(123); + jsonWriter["test_float"].set(51.8); + jsonWriter["test_object"]["test_int"].set(100); + jsonWriter["test_object"]["test_float"].set(100); + + std::string jsonString = jsonWriter.getSerialized(); + cout << jsonString << endl; + + // TehJSON::Tokenizer tokenizer; + // tokenizer.appendInput(jsonString); + // std::vector tokens = tokenizer.tokenize(); + + // for(const auto& token : tokens) + // { + // cout << TehJSON::getTokenName(token.type) << ": " << token.content << endl; + // } + + TehJSON::JSON jsonReader; + cout << "Reading: " << endl; + jsonReader.readFromString(jsonString); + cout << jsonReader.getSerialized() << endl; } -- cgit v1.2.3