Objective:
- This code involves reading, modifying, and adding methods to the JSON file.
- Radir button in WTL and set optional and cancel optional
Example: the desired header file:
#include <json.h> #include <file_io.h>
Code section:
The Read download line displays void Cmaindlg::read_download_line_from_cfg () {std_string strdownloadline;file_io< in the Radir button on the interface. > Json_file ("C://test.json", "R"); Json_value<> json_values_data;if (Json_parse (Json_values_data, Json_file)) {strdownloadline = Json_values_ data["Deflink"].get_string (); Read the value of the Deflink field in the JSON file if (Strdownloadline = = "1") {CButton btn; btn. Attach (GetDlgItem (idc_radio_one). m_hwnd); Btn. SetCheck (TRUE); Method of modifying Radir button state in WTL json_file.close ();} else if (Strdownloadline = = "2") {CButton btn;btn. Attach (GetDlgItem (idc_radio_two) m_hwnd); btn. SetCheck (True); Json_file.close ();}}} If you want to modify the values in the JSON file, you need to read them first, and then use Json_pretty_write to modify the void Cmaindlg::update_cfg_config () {file_io<> json_file ("C ://test.json "," r+ ");json_value<> json_values_data;if (Json_parse (Json_values_data, Json_file))// Read the JSON file into Json_values_data {json_file.close ();} Else{return;} BOOL Isneedupate = json_values_data["Flag"].is_string (); Determines if the Flag field is a string (this is used to determine if the flag field exists) if (isneedupate) {return;} Json_values_data["Deflink"] = "ct"; Modify Deflink field ctjson_values_data["flag"] = "new"; If flag is not present, add the Flag field json_values_data["Notify"] = "http://www.baidu.com"; Add Notify Field file_io<> f_l_cfg ("C://test.json", "W"), Json_pretty_write (F_l_cfg, Json_values_data, ""); Re-write the Test.json file in F_l_cfg.close (); Remember to close the file when you're done with it}
How to read, modify, and add fields to JSON files in VC