我正在为C#中的iOS开发Xamarin项目。从Json列表填充TableView
我有一个包含4个项目的Json文件。我希望他们填充TableView,但只显示Json文件中的最后一项。
这是我得到的JSON文件列表:
StreamReader strm = new StreamReader (filePath);
response = strm.ReadToEnd();
List<Field> items = JsonConvert.DeserializeObject<List<Field>>(response);
为了显示这些项目的TableView中我创建了一个这样的数组:
int count = items.Count;
string[] tableItems = new string[count];
我试图填补该阵列是这样的:
foreach(Field item in items)
{
tableItems = new string[] { item.Value };
}
table.Source = new TableSource(tableItems);
Add(table);
这是TableSource:
public TableSource (string[] items)
{
TableItems = items;
}
这是甚至可能的,我怎样才能实现它,所以我的Json项目是在一个TableView?
编辑
这是Json文件。我分析它只是在一个视图控制器和它的工作,但不是在TableViewController ..
[{
'id': 0,
'type': 'textField',
'value': 'Vul hier je voornaam in.',
'extra': ''
},{
'id': 1,
'type': 'textField',
'value': 'Vul hier je achternaam in.',
'extra': ''
},{
'id': 2,
'type': 'textField',
'value': 'Vul je gebruikersnaam in.',
'extra': ''
},{
'id': 3,
'type': 'textField',
'value': 'Vul je wachtwoord in.',
'extra': 'password'
}]
你可以发布你试图反序列化的JSON吗? – Dave
我检查了foreach循环中tableItems的长度,它始终为1.问题出现在某处.. –