2
我想將JSON數據放入列表中以向用戶顯示記錄。但是當我運行系統時,列表只顯示項目名稱兩次,而不是JSON數據。在Xamarin.forms中顯示帶有JSON數據的列表C#
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實例代碼? – wishmaster
它沒有爲你的列表提供一個模板,它只會顯示每個對象的ToString()值,默認情況下它的類名是 – Jason
我想你還沒有實例化列表:List listaProdutos =新列表(); –