1

Как сериализовать список Items в JSON?

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();            
    }

    int poss = 10;
    List<String> Items = new List<string>();             

    public void addItem(string Text, bool Checked)
    {
        ToDo_Item item = new TestToDo.ToDo_Item(Text, Checked);
        visitor.Controls.Add(item);
        item.Top = poss;
        poss = (item.Top + item.Height + 10);
    }

    private void bunifuImageButton1_Click(object sender, EventArgs e)
    {
        addItem(txt.Text, false);
        Items.Add(txt.Text);
        txt.Text = "";
    }           
}

1 ответ 1

2

1) Устанавливаем Newtonsoft.Json

PM> Install-Package Newtonsoft.Json -Version 10.0.3 

2) Сериализуем ваш список в JSON так:

var json = JsonConvert.SerializeObject(Items);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.