I'm new to Xamarin and using JSON as well.
I'm using an REST API from our ERP system to get the data, and I'm able to do so without problem.
My problem is that I'm unable to figure out how to get the data into a list view correctly. I've tried several threads on stack overflow and I'm not having any success.
Here is the JSON data below:
{
"odata.metadata":"https://ERPSERVER&$select=PartNum,%20PartDescription","value":[
{
"PartNum":"A1","PartDescription":"A1DescHere"
},{
"PartNum":"A2","PartDescription":"A2DescHere"
}
]
}
Here is the XAML code for the list
<ListView x:Name="PartList" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding PartNum}" Detail="{Binding PartDescription}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I am running in circles, here is some of the code I have tested:
string str = json.Substring(json.IndexOf("["));
string str2 = str.Replace("[", "").Replace("]","").TrimEnd('}');
Part part = JsonConvert.DeserializeObject<Part>(str2);
PartNum.Text = part.PartNum;
PartDescription.Text = part.PartDescription;
I had to use substring and replace to remove some of the odata to get the DeserializeObject correctly.
Can anyone help point me in the right direction?
Thanks all!