In C # UWP I would like to display the data from the Zomato API via Gridview, but when I run the following code there is no result. In the meantime, when I run the API in the browser, the json code works. Please help me. Thank you!
XAML code here:
<PivotItem Header="Restoranlar">
<Grid SizeChanged="Grid_SizeChanged" Background="{ThemeResource SystemBaseLowColor}">
<GridView x:Name="itemGridView">
<GridView.ItemTemplate>
<DataTemplate x:DataType="local:Restaurant">
<Grid>
<Image x:Name="menu" Source="{x:Bind photos_url}" HorizontalAlignment="Center" Stretch="Uniform"/>
<StackPanel Margin="0,-25,0,0" Height="25" VerticalAlignment="Bottom">
<TextBlock x:Name="name" Text="{x:Bind name}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" Foreground="White" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="SemiBold"/>
</StackPanel>
<TextBlock x:Name="ID" Text="{x:Bind url}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" Foreground="White" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="SemiBold"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</PivotItem>
C# code here:
private async void GetRestaurants()
{
try
{
string strBingImageURL = string.Format("https://developers.zomato.com/api/v2.1/search?apikey=" + APIKEY +"&count=10&lat=" + LatitudeF + "&lon=" + LongitudeF + "&category=restaurants&sort=real_distance&order=asc");
string jsonText = "";
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(new Uri(strBingImageURL));
jsonText = await response.Content.ReadAsStringAsync();
JsonArray jsonData1 = JsonArray.Parse(jsonText);
foreach (JsonValue groupValue in jsonData1)
{
if (jsonData1.Count > 0)
{
JsonObject groupObject = groupValue.GetObject();
string zname = groupObject["name"].GetString();
string zphotos = groupObject["photos_url"].GetString();
string zurl = groupObject["url"].GetString();
Restaurant file = new Restaurant();
file.name = zname;
file.url = zurl;
file.photos_url = zphotos;
}
else
{
//DoNothing
}
}
}
catch (HttpRequestException ex)
{
//Catch Here
}
}
Restaurant class here:
public class Restaurant
{
public string name { get; set; }
public string url { get; set; }
public string photos_url { get; set; }
}
ObservableCollectionorListof some sort? If that is the case you are missing yourItemsSourceproperty on theGridView, this would explain why you see nothing.