Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# fetch-data-using-webapi-treeview-xamarin
How to fetch data using Web API in Xamarin.Forms TreeView
This repository showcases how to populate the Syncfusion Xamarin.Forms TreeView control with hierarchical data fetched from a Web API. The included sample demonstrates making HTTP requests to retrieve JSON data, deserializing the response into a suitable object hierarchy, and binding the result to the TreeView.

## Sample

### Helper
```csharp
internal class WebApiServices
{
public static string webApiUrl = "Your URL"; // Your Web Api here

System.Net.Http.HttpClient client;

public WebApiServices()
{
client = new System.Net.Http.HttpClient();
}

public async System.Threading.Tasks.Task<ObservableCollection<RootTree>> RefreshDataAsync()
{
var uri = new Uri(webApiUrl);
try
{
//Sends request to retrieve data from the web service for the specified Uri
var response = await client.GetAsync(uri);

if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync(); //Returns the response as JSON string
return JsonConvert.DeserializeObject<ObservableCollection<RootTree>>(content); //Converts JSON string to ObservableCollection
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(@"ERROR {0}", ex.Message);
}

return null;
}
}
```

## Requirements to run the demo

To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)

## Troubleshooting
### Path too long exception
If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.