Add json test

This commit is contained in:
daleclack 2023-01-29 14:13:45 +08:00
parent 0fa0a40d86
commit 83aeac4ee5
2 changed files with 56 additions and 0 deletions

View File

@ -8,6 +8,7 @@ MyPrefs::MyPrefs(){
ref_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/prefs_stack.ui");
// Initalize title widget
// Add stack switcher to the titlebar
stack_switcher = ref_builder->get_widget<Gtk::StackSwitcher>("stack_switch");
header.set_title_widget(*stack_switcher);
header.set_decoration_layout("close:menu");

View File

@ -0,0 +1,55 @@
/*
A test for json library from nlohmann,
the json object will be a data of the json file
2023/1/29 dale clack
*/
#include "../../json_nlohmann/json.hpp"
#include <iostream>
#include <fstream>
using json = nlohmann::json;
// Function pointer
typedef void (*funcs)();
void read_json_file()
{
}
void create_json_file()
{
// Create json data
json data = json::parse(R"(
{
data1 : {},
data2 : {}
}
)");
// Create json object for a key
// json data2 = json::parse(R"(
// {
// test1:2,
// test2:3
// }
// )");
// data["data2"] = data;
// auto data2 = data["data2"];
// std::cout << data2 << std::endl;
// Save data to a json file
std::fstream outfile;
outfile.open("test.json", std::ios_base::out);
if (outfile.is_open())
{
outfile << data;
}
outfile.close();
}
int main()
{
create_json_file();
return 0;
}