C#Json根据组合框选择值

时间:2018-01-04 13:23:35

标签: c# json checkbox combobox textbox

我有以下情况:我正在使用组合框,复选框,按钮和文本框处理Windows窗体。

我有以下json:

{
"SDEOptions": [
    {
        "name": "Option 1",
        "attributes": [
            {
                "description": "some text here",
                "otherDescription": "more complex here if checkbox is checked",
                "question": "Checkbox checked?"
            }
        ]
    },
    {
        "name": "Option 2",
        "attributes": [
            {
                "description": "some text here",
                "otherDescription": "more complex here if checkbox is checked",
                "question": "Checkbox checked?"
            }
        ]
    }
]}

我想在组合框中选择的特定选项中显示说明或otherDescription属性(如果选中复选框)。

现在我已经设法使用JSON中的名称属性填充组合框,如下所示:

var rootObj = SdeOptions.FromJson(File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Data\\Options.json")));
if (rootObj == null) return;
foreach (var name in rootObj.SDEOptions)
{
    boxOptions.Items.Add(name.name);

}
boxOptions.Sorted = true;

刚刚开始倾向于使用c#和Json,说实话我真的不知道这是否是我应该使用的正确的json格式。

0 个答案:

没有答案