0

I have the following situation: I am working on a windows form with a combobox, a checkbox, a button and a text box.

I have the following 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?"
            }
        ]
    }
]}

I would like to display the description or otherDescription property (if checkbox is checked) for the specific Option selected in the combobox.

For now I have managed to fill the combobox with the name properties from JSON like so:

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;

Just started to lean c# and Json, and to be honest I really do not know if this is the correct json format I should use.

Ali Azam
  • 2,047
  • 1
  • 16
  • 25
Myh
  • 95
  • 1
  • 9
  • this is nice mixture ```Path.Combine(Environment.CurrentDirectory, "Data\\Options.json")``` use this instead ```Path.Combine(Environment.CurrentDirectory, "Data","Options.json")``` for real OS independence – FrankM Jan 04 '18 at 13:46
  • this will help you: https://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe – FrankM Jan 04 '18 at 13:55

0 Answers0