I'm trying to do something that gives me output like this:
[
{
"Nome": "João",
"Comprou": [
"Carro": "Sedan", "Preco": "12000",
"Moto": "Honda", "Preco": "8000"
]
}
]
For this I use List and to save JSON.net usage. The problem is that I can not put a key inside another. I tried this way:
public class Cliente
{
public string Nome { get; set; }
public string[] Comprou { get; set; }
}
public static List<Cliente> Clientes = new List<Cliente>();
I do not know how to assign one value within another. I want to get the products and put them in a listbox for the particular client that is selected in another listbox. I tried using foreach:
Cliente cliente = Clientes[listaClientes.SelectedIndex];
foreach (var produto in cliente.Comprou)
{
listaProdutosComprados.Items.Add(produto);
}
I wanted to put the values as "Name" and "Price" just like I did with the client so that I can then display these values in a label or textbox. I'm developing this project in C # with a WinForms application.