0
I am having difficulty to perform a query in an external Tinyerp Restapi to consult and include requests via an app created in my company, some difficulty is to use json because I am new to xamrin and an Asp.net framework application is working properly. Follow the json2csharp created model:
public class Pedido2
{
public string id { get; set; }
public string numero { get; set; }
public object numero_ecommerce { get; set; }
public string data_pedido { get; set; }
public string data_prevista { get; set; }
public string nome { get; set; }
public double valor { get; set; }
public string id_vendedor { get; set; }
public string nome_vendedor { get; set; }
public string situacao { get; set; }
public string codigo_rastreamento { get; set; }
public object url_rastreamento { get; set; }
}
public class Pedido1
{
public Pedido2 pedido { get; set; }
}
public class Retorno
{
public string status_processamento { get; set; }
public string status { get; set; }
public string pagina { get; set; }
public string numero_paginas { get; set; }
public List<Pedido1> pedidos { get; set; }
}
public class RootObject
{
public Retorno retorno { get; set; }
}
and follow page.Cs:
using MacVendas.Models.API;
using Newtonsoft.Json;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using static MacVendas.Models.API.Pedido;
namespace MacVendas.Pages
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ProdutoPage : ContentPage
{
public ProdutoPage()
{
InitializeComponent();
//Iniciar();
this.BindingContext = new Pedido();
}
private void Iniciar()
{
var client = new HttpClient();
var resp = client.GetAsync("https://api.tiny.com.br/api2/pedidos.pesquisa.php?token=""&formato=json").Result;
string respStr = resp.Content.ReadAsStringAsync().Result;
RootObject ObjContactList = new RootObject();
if (respStr != "")
{
//Converting JSON Array Objects into generic list
ObjContactList = JsonConvert.DeserializeObject<RootObject>(respStr);
}
//Binding listview with server response
listviewConacts.ItemsSource = ObjContactList.retorno.pedidos;
}
}
}
and the page.xmal:
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Margin="10" Text="JSON Parsing" FontSize="25" />
<ListView x:Name="listviewConacts" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True" ItemSelected="listviewContacts_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid HorizontalOptions="FillAndExpand" Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Text="{Binding nome}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="Blue" FontAttributes="Bold"/>
<Label Text="{Binding numero}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange" FontAttributes="Bold"/>
<Label Text="{Binding }" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray" FontAttributes="Bold"/>
<BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="3" HorizontalOptions="FillAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<ActivityIndicator x:Name="ProgressLoader" IsRunning="True"/>
</Grid>
thanks in advance for the help
What is the difficulty you are having? I copied your code here and the object
ObjContactList
is completed correctly in the Json conversion.– Raquel Pinheiro
So when I try to visualize the list nothing appears on my page xaml, it goes blank
– Wesley Henrique
The problem is in
binding
ofListView
that is not taking the propertypedido.nome
and so on. If you can, please edit the title of your question to help other people search.– Raquel Pinheiro