Skip to content

Commit b8bfde4

Browse files
Merge pull request #6 from Santhosh-SF4792/main
update the README.md file
2 parents fb9f5fb + 854d361 commit b8bfde4

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
# fetch-data-using-webapi-treeview-xamarin
2-
How to fetch data using Web API in Xamarin.Forms TreeView
2+
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.
3+
4+
## Sample
5+
6+
### Helper
7+
```csharp
8+
internal class WebApiServices
9+
{
10+
public static string webApiUrl = "Your URL"; // Your Web Api here
11+
12+
System.Net.Http.HttpClient client;
13+
14+
public WebApiServices()
15+
{
16+
client = new System.Net.Http.HttpClient();
17+
}
18+
19+
public async System.Threading.Tasks.Task<ObservableCollection<RootTree>> RefreshDataAsync()
20+
{
21+
var uri = new Uri(webApiUrl);
22+
try
23+
{
24+
//Sends request to retrieve data from the web service for the specified Uri
25+
var response = await client.GetAsync(uri);
26+
27+
if (response.IsSuccessStatusCode)
28+
{
29+
var content = await response.Content.ReadAsStringAsync(); //Returns the response as JSON string
30+
return JsonConvert.DeserializeObject<ObservableCollection<RootTree>>(content); //Converts JSON string to ObservableCollection
31+
}
32+
}
33+
catch (Exception ex)
34+
{
35+
System.Diagnostics.Debug.WriteLine(@"ERROR {0}", ex.Message);
36+
}
37+
38+
return null;
39+
}
40+
}
41+
```
42+
43+
## Requirements to run the demo
44+
45+
To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)
46+
47+
## Troubleshooting
48+
### Path too long exception
49+
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.

0 commit comments

Comments
 (0)