-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
c0da6eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://cpp-by-example.netlify.app as production
🚀 Deployed on https://67422e1cac5179a2e1ac954d--cpp-by-example.netlify.app