Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JSON格式文件加载_C#_Json_List - Fatal编程技术网

C# JSON格式文件加载

C# JSON格式文件加载,c#,json,list,C#,Json,List,所以我有一个列表,它是用我的JSON格式文件编写的。但现在我想加载它。例如,在我的命令行c:\temp\my dir\program.exe test.json上,我希望我使用的复选框选项将在我的窗体窗口中被选中 我的写JSON文件代码: private void SaveConfig(string path) { var config = new DocConfig(); config.Parts = new List<Do

所以我有一个列表,它是用我的JSON格式文件编写的。但现在我想加载它。例如,在我的命令行
c:\temp\my dir\program.exe test.json
上,我希望我使用的复选框选项将在我的窗体窗口中被选中

我的写JSON文件代码:

private void SaveConfig(string path)
        {
            var config = new DocConfig();
            config.Parts = new List<DocPart>();


            foreach(var checkbox in _checkBoxes)
            {
                config.Parts.Add(new DocPart { Checked = checkbox.Checked, Title = checkbox.Text });
            }

            var configString = config.SaveToString();
            File.WriteAllText(path, configString);
但什么也没发生:/这里需要帮助:)


谢谢。

什么是
DocConfig
?你试过调试看看会发生什么吗?是的,我刚调试过。我在if语句之后写Debug.WriteLine,它会打印8次。那么我的if语句有什么问题吗?您是否查看了
config.Parts
中的值?是否有
部分
标题
与这些复选框的
文本
属性相同?换言之,逐步完成代码并检查对象。也许您的
DocConfig
不起作用了?一切看起来都正常,一切看起来都正常。如何使其通过命令行运行。与program.exe test.dconf和my program一样,我的程序会立即在program.exe中选中my test.dconf设置复选框
 var cfgstring = File.ReadAllText(@"C:temp\test.json");


var cfg = DocConfig.LoadFromString(cfgString);

        foreach (var part in config.Parts)
        {
            if (part.Title == checkBox1.Text)
               checkBox1.Checked = part.Checked;


            if (part.Title == checkBox2.Text)
                checkBox2.Checked = part.Checked;
        }