Hello,
First of all Im scanning the qr code with the application, then the app is making api request and I get json in my response from my server..
I want to get a json from my api and display it in picker in xaml, let me show you my json
{"20":[{"stroke":"25","id":"1222","price":"118.00"},{"stroke":"40","id":"1224","price":"121.60"},"25":[{"stroke":"25","id":"1247","price":"126.75"},{"stroke":"40","id":"1248","price":"130.80"},........
Where "20" and "25" are the diameters and must be unique values that have to be in the 1st picker while in the 2nd picker I need to have stroke, id and price.
Here is my model;
public class Silowniki
{
//public string Dia { get; set; }
public string stroke { get; set; }
public string id { get; set; }
public string cena { get; set; }
}
public class Diameter
{
public List<Silowniki> diameter { get; set; }
}
My viewmodel
public class ScannedViewModel : INotifyPropertyChanged
{
public ObservableCollection<Silowniki> Silowniki { get; set; }
public ObservableCollection<Diameter> Dia { get; set; }
public string Test { get; set; }
public ScannedViewModel()
{
Silowniki = new ObservableCollection<Silowniki>();
Dia = new ObservableCollection<Diameter>();
}
My json response here:
if (response.StatusCode == HttpStatusCode.OK)
{
Console.WriteLine("Tutaj jest twoj response");
var a = JsonConvert.DeserializeObject(responseText);
Debug.WriteLine(a);
//Console.WriteLine(a);
return a;
And here is how I add the json to diameter, I doubt its the right way..
public Diameter MyDia { get; set; }
ScannerPage.OnScanResult += (result) =>
{
ScannerPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
dynamic jsonRespone = await ConnectWithOauth.GetRequest(result.Text);
JObject parsedJson = JObject.Parse(jsonRespone);
MyDia = JsonConvert.DeserializeObject<Diameter>(jsonRespone);
//Console.WriteLine(MyDia);
//Console.WriteLine(jsonRespone);
//SaveProducts(parsedJson, viewModel);
viewModel.Dia.Add(MyDia);
ScannedProducts nextPage = new ScannedProducts(viewModel);
nextPage.BindingContext = viewModel;
Console.WriteLine("Pokaz mydia count: " + MyDia.diameter.Count);
^- Here im getting error from the compiler
await Navigation.PushAsync(nextPage);
I have also tried with my "SaveProducts" function here it is:
async public void SaveProducts(dynamic json, ScannedViewModel model)
{
//ScannedProducts nextPage = new ScannedProducts(model);
foreach (var item in json)
{
foreach (var prop in item)
{
foreach (var test in prop)
{
Silownik = new Silowniki
{
//Dia = item.Name,
stroke = Convert.ToString(test[0]).Split(':')[0],
id = Convert.ToString(test[0]).Split(':')[1],
cena = Convert.ToString(test[0]).Split(':')[2]
};
//Console.WriteLine(Silownik.Dia + ":" + Silownik.Cena);
try
{
model.ItemOb.Add(Item);
model.Silowniki.Add(Silownik);
model.Dia.Add(MyDia);
}
catch (Exception e)
{
Debug.Write(e);
}
}
}
}
And lastly here is my xaml and Im 100% sure its wrong..
<StackLayout x:Name="myStackLayout">
<Label
x:Name="idKlienta"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Picker Title="Wybierz Diameter"
ItemsSource="{Binding Dia}"
ItemDisplayBinding="{Binding Silowniki.stroke}">
</Picker>
<Picker Title="Skok"
ItemsSource="{Binding Dia}"
ItemDisplayBinding="{Binding Silowniki}">
</Picker>
Please help me Im stuck in this for past 2 days and I really dont know what to do next...