我有一个要在列表框中显示的时区JSON数组。
JSON结构:
[
{
"value": "Dateline Standard Time",
"abbr": "DST",
"offset": -12,
"isdst": false,
"text": "(UTC-12:00) International Date Line West"
},
{
"value": "UTC-11",
"abbr": "U",
"offset": -11,
"isdst": false,
"text": "(UTC-11:00) Coordinated Universal Time-11"
}
]在加载应用程序时,我加载了JSON结果。
在应用程序中加载JSON:
public Form1()
{
InitializeComponent();
LoadJson();
}
public void LoadJson()
{
using (StreamReader r = new StreamReader("timeZones.json"))
{
string json = r.ReadToEnd();
List<TimeZones> timeZones = JsonConvert.DeserializeObject<List<TimeZones>>(json);
listBox1.DataSource = timeZones;
}
}
}
public class TimeZones
{
public string Value { get; set; }
public string Abbr { get; set; }
public string Offset { get; set; }
public string IsDst { get; set; }
public string Text { get; set; }
}当我将这个列表作为数据源添加到我的列表框中时,我会得到以下内容,可以让每一行显示值、缩写、偏移量isDst和文本吗?我遗漏了什么?

发布于 2014-12-19 14:32:22
最简单的方法是像这样覆盖TimeZones的TimeZones方法:
public override string ToString()
{
return string.Format("{0}, {1}, {2}, {3}, {4}",
Value, Abbr, Offset, IsDst, Text);
}参考资料:http://msdn.microsoft.com/library/system.object.tostring%28v=vs.110%29.aspx
https://stackoverflow.com/questions/27567901
复制相似问题