Documentos de Académico
Documentos de Profesional
Documentos de Cultura
<ScrollView>
<VerticalStackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Así se ve la aplicación
Ahora agregaremos el Nuguet Newtonsoft.Json para poder deserealizar las cadenas en formato
JSON.
List<Usuarios> registros;
HttpClient client;
public MainPage()
{
InitializeComponent();
lst.ItemsSource = new List<Usuarios>() {
new Usuarios() {
nombre = "Becky G", idpersona = 1, usuario = "bbbhyyy",
contrasena="choforo"
},
new Usuarios() {
nombre = "Burro Banrankin", idpersona = 2, usuario = "burro",
contrasena="medusa"
},
};
client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
string direccion =
"https://pmoviles2.000webhostapp.com/api/listar.php";
var uri = new Uri(string.Format(direccion, string.Empty));
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
registros = JsonConvert.DeserializeObject<List<Usuarios>>(content);
string s = "";
registros.ForEach(delegate (Usuarios x)
{
Console.WriteLine(x.nombre);
s = s + x.nombre + "\n";
});
string mensaje = registros.Count + " Registros \n" + s;
await DisplayAlert("Se cargaron ", mensaje, "OK");
}
}
}
private async void lst_ItemTapped(object sender, ItemTappedEventArgs e)
{
var elemento = e.Item as Usuarios;
}
}