【发布时间】:2016-06-09 16:35:58
【问题描述】:
我在绑定从某个网站收到的对象时遇到问题,我已经创建了所需的必要模型并验证了信息是否正确,所以我知道我正在获取我的信息,问题是我正在尝试用某些信息制作一个网格,我无法使用绑定功能处理它,似乎没有显示任何内容 上下文:我正在使用 Xamarin 制作移动应用程序,我也在使用 REST 来接收某些信息
Transactions.TransactionList transactionmade = JsonConvert.DeserializeObject<Transactions.TransactionList>(result);
//这里用来接收信息没问题
_listView = new ListView
{
HasUnevenRows = true,
Margin = 10,
SeparatorColor = Color.Teal
};
_listView.ItemsSource = transactionmade.transactions;
_listView.ItemTemplate = validDataTemplate;
如果我做一个简单的foreach也没问题,它会显示我需要的信息
foreach (var item in transactionmade.transactions)
{
Debug.WriteLine("id=={0} .. holder=={1} .. value=={2}",
item.id, item.counterparty.holder.name, item.details.value.amount);
}
//在我需要访问第二和第三级信息的绑定中出现问题,并非所有代码都在这里,但我认为这很容易理解,这在我创建的有效模板函数中
idLabelholder.SetBinding(Label.TextProperty, "account: {id}");
dateofCompletionLabel.SetBinding(Label.TextProperty, "details: {completed };
amountLabel.SetBinding(Label.TextProperty, "details: {value: {amount }}");
balanceLabel.SetBinding(Label.TextProperty, "details: {new_balance: {amount }}");
这是使用的模型
public class Holder
{
public string name { get; set; }
public bool is_alias { get; set; }
}
public class Bank
{
public string national_identifier { get; set; }
public string name { get; set; }
}
public class Account
{
public string id { get; set; }
public List<Holder> holders { get; set; }
public string number { get; set; }
public object kind { get; set; }
public object IBAN { get; set; }
public object swift_bic { get; set; }
public Bank bank { get; set; }
}
public class Holder2
{
public string name { get; set; }
}
public class Bank2
{
public string national_identifier { get; set; }
public string name { get; set; }
}
public class Counterparty
{
public string id { get; set; }
public Holder2 holder { get; set; }
public string number { get; set; }
public object kind { get; set; }
public object IBAN { get; set; }
public object swift_bic { get; set; }
public Bank2 bank { get; set; }
}
public class NewBalance
{
public string currency { get; set; }
public string amount { get; set; }
}
public class Value
{
public string currency { get; set; }
public string amount { get; set; }
}
public class Details
{
public string type { get; set; }
public string description { get; set; }
public string posted { get; set; }
public string completed { get; set; }
public NewBalance new_balance { get; set; }
public Value value { get; set; }
}
public class Transaction
{
public string id { get; set; }
public Account account { get; set; }
public Counterparty counterparty { get; set; }
public Details details { get; set; }
}
public class TransactionList
{
public List<Transaction> transactions { get; set; }
}
这里是接收到的信息的简单示例
{
"transactions": [
{
"id": "065bf1e2-c39c-49b9-98ca-2604db647284",
"account": {
"id": "somebodymillionaire",
"holders": [
{
"name": "somebody1",
"is_alias": false
}
],
"number": "8585757136",
"kind": null,
"IBAN": null,
"swift_bic": null,
"bank": {
"national_identifier": "rbs",
"name": "The Royal Bank of Scotland"
}
},
"counterparty": {
"id": "f39f20a3-15ff-475e-b654-d377df58ee5d",
"holder": {
"name": "somebodycounter"
},
"number": "8964202115",
"kind": null,
"IBAN": null,
"swift_bic": null,
"bank": {
"national_identifier": "rbs",
"name": "The Royal Bank of Scotland"
}
},
"details": {
"type": "sandbox-payment",
"description": "im a millionaire",
"posted": "2016-06-07T20:36:40Z",
"completed": "2016-06-07T20:36:40Z",
"new_balance": {
"currency": "EUR",
"amount": "9449.47"
},
"value": {
"currency": "EUR",
"amount": "-550.53"
}
}
}]}
显示的信息是
App.Models.Transactions+Transaction
现在我知道这是来自我创建的列表视图的响应,但是我如何显示我为显示该列表中其他层所要求的信息而制作的绑定标签 大部分示例都是第 1 层 json 列表,所以我如何获取其他层的信息
我做错了什么? 谢谢你的高级:)
【问题讨论】: