Skip to content

Commit

Permalink
Fix json
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Nov 23, 2024
1 parent 7e9fb5a commit c0da6eb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions serialization/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

include(FetchContent)

FetchContent_Declare(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS NAMES nlohmann_json
)

FetchContent_GetProperties(nlohmann_json)
FetchContent_MakeAvailable(nlohmann_json)

add_executable(json_test json.cpp)
target_link_libraries(json_test
PUBLIC nlohmann_json::nlohmann_json
)

configure_file(example.json ${CMAKE_CURRENT_BINARY_DIR}/example.json COPYONLY)
8 changes: 8 additions & 0 deletions serialization/json/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": "register",
"register": {
"game_name": "game_name",
"game_version": "game_version",
"token": "token"
}
}
26 changes: 26 additions & 0 deletions serialization/json/json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main(int argc, char const *argv[])
{
std::string game_name = "the_last_samurai";
std::string game_version = "0.1.0";
std::string token = "cc1e240aacb641fed0050d2c2f16db918b4a7c10";

json j = {
{"command", "register"},
{"register", {
{"game_name", game_name},
{"game_version", game_version},
{"token", token},
}}
};

std::string data_to_send = j.dump();

std::cout << j.dump(4) << std::endl;

return 0;
}

1 comment on commit c0da6eb

@mikolasan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.