How to read, modify, and add fields to JSON files in VC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.