我的Windows Phone应用程序上有一个列表框,列表框从集合中接收值。我将Listbox项目放在数组上。所以,我需要获取第一个列表项的值,但我收到了值App1.PivotPage1+Fields
。
我要展示的收藏品是FNome
。怎么做?
我的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
string[] array = new string[List2.Items.Count];
for (int i = 0; i < List2.Items.Count; i++)
{
object s = List2.Items[i];
array[i] = s.ToString();
}
TJSONObject jObject = new TJSONObject();
TJSONPair jPair = new TJSONPair("test", array[0]);
TJSONPair jPair1 = new TJSONPair("test1", "test1");
TJSONArray jArray = new TJSONArray();
jObject.addPairs(jPair);
jObject.addPairs(jPair1);
jArray.add(jObject);
MessageBox.Show(jArray.ToString());
}
我的收藏:
public ObservableCollection<Fields> Items { get; set; }
public class Fields
{
[JsonProperty(PropertyName = "FId")]
public int FId { get; set; }
public string FNome { get; set; }
public float FEstado1 { get; set; }
public string FPais { get; set; }
public string Quantity { get; set; }
public string lero { get; set; }
public string Quantity1 { get; set; }
public string FEstado { get; set; }
}
答案 0 :(得分:0)
我的代码现在运行正常。我只更改了这段代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
string[] array = new string[List2.Items.Count];
for (int i = 0; i < List2.Items.Count; i++)
{
object s = List2.Items[i];
array[i] = s.ToString();
}
TJSONObject jObject = new TJSONObject();
TJSONPair jPair = new TJSONPair("test", array[0]);
TJSONPair jPair1 = new TJSONPair("test1", "test1");
TJSONArray jArray = new TJSONArray();
jObject.addPairs(jPair);
jObject.addPairs(jPair1);
jArray.add(jObject);
MessageBox.Show(jArray.ToString());
}
为此:
private void Button_Click(object sender, RoutedEventArgs e)
{
Fields[] array = List2.Items.Cast<Fields>().ToArray();
TJSONObject jObject = new TJSONObject();
TJSONPair jPair = new TJSONPair("FNome", array[0].FNome);
TJSONPair jPair1 = new TJSONPair("test1", "test1");
TJSONArray jArray = new TJSONArray();
jObject.addPairs(jPair);
jObject.addPairs(jPair1);
jArray.add(jObject);
MessageBox.Show(jArray.ToString());
}