【发布时间】:2017-01-21 11:00:14
【问题描述】:
我想将 JSON 数据放在一个列表中以向用户显示记录。但是当我运行系统时,列表只显示了两次项目名称,而不是 JSON 数据。
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("Http://www.eletrotechautomacoes.com.br");
string url = string.Format("/pontos/consulta.php");
var response = await client.GetAsync(url);
var result = response.Content.ReadAsStringAsync().Result;
List<ExchangeRates> listaProdutos = JsonConvert.DeserializeObject<List<ExchangeRates>>(result);
this.LlistSpecials.ItemsSource = listaProdutos;
我认为错误在这一行:
this.LlistSpecials.ItemsSource = listaProdutos;
我的困难是显示列表中的内容。我需要对要显示的列表进行一些转换吗?您知道显示此列表的程序吗?它目前正在返回项目名称两次。我认为这与 JSON 项目的数量有关,这也是两个。
文件 JSON:
[{
"id": "1",
"nome": "pendrive",
"preco": "20.00",
"tipo": "eletronico"
}, {
"id": "2",
"nome": "Monitor",
"preco": "250.00",
"tipo": "eletronicos"
}]
对象:
public class ExchangeRates
{
public string id { get; set; }
public string nome { get; set; }
public string preco { get; set; }
public string tipo { get; set; }
}
【问题讨论】:
-
您能发布您的 Xaml 或 ListView 实例化代码吗?
-
如果您没有为列表提供模板,它只会显示每个对象的 ToString() 值,默认情况下将是类的名称
-
我认为您还没有实例化列表: List
listaProdutos = new List ();