Add json test
This commit is contained in:
parent
0fa0a40d86
commit
83aeac4ee5
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue