如何在数据网格中显示JSON文件中的字符串列表?

时间:2018-11-12 19:23:32

标签: json list datagridview

对象类:

public class SIReport
{
    public string Sortcode { get; set; }
    public string Incident { get; set; }
}

public class Message
{
    public bool IsSIR { get; set; }
    public string Header { get; set; }
    public string Subject { get; set; }
    public List<string> Hashtags { get; set; }
    public List<string> URLs { get; set; }
    public SIReport SIReport { get; set; } 

}

我首先以JSON格式读取文本文件

string jsonData = File.ReadAllText(@"C:\text.txt");

var messageList = JsonConvert.DeserializeObject<List<Message>>(jsonData);

文件如下:

{
  "IsSIR": true,
  "Header": "E123456789",
  "Subject": "SIR Subject Line",
  "Hashtags": [
     "#hasttag",
     "#hashtag2"
  ],
  "URLs": [
    "www.google.com",
    "www.stackoverflow.com"
  ],
  "SIReport": {
    "Sortcode": "98-23-43",
    "Incident": "N/A"
  }
}

然后我只需将列表绑定到ItemsSource

Datagrid_Msg.ItemsSource = messageList;

它显示字符串没有问题,但是在“列表”列下它仅显示“(Collection)”。我该如何显示那些字符串列表?

0 个答案:

没有答案