diff --git a/README.md b/README.md index c73bc44..3b699be 100644 --- a/README.md +++ b/README.md @@ -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> 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>(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.