{"id":23061512,"url":"https://github.com/syncfusionexamples/json-online-data-listview-xamarin","last_synced_at":"2026-05-02T19:33:44.141Z","repository":{"id":98095996,"uuid":"296598015","full_name":"SyncfusionExamples/json-online-data-listview-xamarin","owner":"SyncfusionExamples","description":"This repository contains the sample about how to bind online JSON data to Xamarin.Forms ListView (SfListView)","archived":false,"fork":false,"pushed_at":"2025-09-13T10:36:47.000Z","size":567,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-13T12:54:15.911Z","etag":null,"topics":["json","json-data","listview","xamarin-forms"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyncfusionExamples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-18T11:11:41.000Z","updated_at":"2025-09-13T10:36:51.000Z","dependencies_parsed_at":"2025-02-09T23:32:53.562Z","dependency_job_id":null,"html_url":"https://github.com/SyncfusionExamples/json-online-data-listview-xamarin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SyncfusionExamples/json-online-data-listview-xamarin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fjson-online-data-listview-xamarin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fjson-online-data-listview-xamarin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fjson-online-data-listview-xamarin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fjson-online-data-listview-xamarin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyncfusionExamples","download_url":"https://codeload.github.com/SyncfusionExamples/json-online-data-listview-xamarin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fjson-online-data-listview-xamarin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32547647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T19:18:06.202Z","status":"ssl_error","status_checked_at":"2026-05-02T19:16:21.335Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","json-data","listview","xamarin-forms"],"created_at":"2024-12-16T03:17:42.867Z","updated_at":"2026-05-02T19:33:44.124Z","avatar_url":"https://github.com/SyncfusionExamples.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to bind online JSON data to Xamarin.Forms ListView (SfListView)\n\nYou can fetch data from a web server and store it on a local server for Xamarin.Forms [SfListView](https://help.syncfusion.com/xamarin/listview/overview). You can refer to the document regarding offline JSON with ListView from [here](https://www.syncfusion.com/kb/11173/how-to-bind-json-data-to-xamarin-forms-listview-sflistview).\n\nYou can also refer the following article.\n\nhttps://www.syncfusion.com/kb/11943/how-to-bind-online-json-data-to-xamarin-forms-listview-sflistview\n\n**XAML**\n\nCreate Xamarin.Forms application with **SfListView**.\n``` xml\n\u003cContentPage xmlns=\"http://xamarin.com/schemas/2014/forms\"\n             xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"\n             xmlns:local=\"clr-namespace:ListViewXamarin\"\n             xmlns:syncfusion=\"clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms\"\n             xmlns:data=\"clr-namespace:Syncfusion.DataSource;assembly=Syncfusion.DataSource.Portable\"\n             x:Class=\"ListViewXamarin.MainPage\" Padding=\"{OnPlatform iOS='0,40,0,0'}\"\u003e\n    \u003cContentPage.BindingContext\u003e\n        \u003clocal:ListViewModel/\u003e\n    \u003c/ContentPage.BindingContext\u003e\n    \n\t \u003cContentPage.Content\u003e\n        \u003cStackLayout\u003e\n            \u003cGrid BackgroundColor=\"#2196F3\" HeightRequest=\"40\"\u003e\n                \u003cLabel Text=\"To Do Items\" x:Name=\"headerLabel\"  TextColor=\"White\" FontAttributes=\"Bold\" VerticalOptions=\"Center\" HorizontalOptions=\"Center\" /\u003e\n            \u003c/Grid\u003e\n            \u003csyncfusion:SfListView x:Name=\"listView\" ItemSize=\"60\" GroupHeaderSize=\"50\" BackgroundColor=\"#FFE8E8EC\" ItemsSource=\"{Binding Items}\"\u003e\n                \u003csyncfusion:SfListView.ItemTemplate \u003e\n                    \u003cDataTemplate\u003e\n                        ...\n                    \u003c/DataTemplate\u003e\n                \u003c/syncfusion:SfListView.ItemTemplate\u003e\n                \u003csyncfusion:SfListView.DataSource\u003e\n                    \u003cdata:DataSource\u003e\n                        \u003cdata:DataSource.GroupDescriptors\u003e\n                            \u003cdata:GroupDescriptor PropertyName=\"userId\"/\u003e\n                        \u003c/data:DataSource.GroupDescriptors\u003e\n                    \u003c/data:DataSource\u003e\n                \u003c/syncfusion:SfListView.DataSource\u003e\n                \u003csyncfusion:SfListView.GroupHeaderTemplate\u003e\n                    \u003cDataTemplate\u003e\n                       ...\n                    \u003c/DataTemplate\u003e\n                \u003c/syncfusion:SfListView.GroupHeaderTemplate\u003e\n            \u003c/syncfusion:SfListView\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ContentPage.Content\u003e\n\u003c/ContentPage\u003e\n```\n**C#**\n\nFetch data and download from the web server.\n\n1. Using the [HTTPClient.GetAsync](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getasync?view=netcore-3.1) method, retrieve data from the web server for the specified URL.\n\n2. The [HTTPContent.ReadAsStreamAsync](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent.readasstreamasync?view=netcore-3.1) returns the data in stream format.\n\n3. Use [Environment.GetFolderPath](https://docs.microsoft.com/en-us/dotnet/api/system.environment.getfolderpath?view=netcore-3.1) method to create a local path to store the retrieved data and combine 4. the path with the file name using [Path.Combine](https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netcore-3.1) method.\n\n5. The [FileInfo.OpenWrite](https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo.openwrite?view=netcore-3.1#System_IO_FileInfo_OpenWrite) creates a write only stream and write to the local file stream using [CopyToAsync](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync?view=netcore-3.1#System_IO_Stream_CopyToAsync_System_IO_Stream_) method.\n\n``` c#\nnamespace ListViewXamarin\n{\n    public class DataServices\n    {\n        private static HttpClient httpClient;\n\n        public DataServices()\n        {\n            httpClient = new HttpClient();\n        }\n\n        /// \u003csummary\u003e\n        /// Fetches data from web server and write it to the local file.\n        /// \u003c/summary\u003e\n        /// \u003creturns\u003eReturns true, if data fetched from webserver and downloaded to the local location.\u003c/returns\u003e\n        public async Task\u003cbool\u003e DownloadJsonAsync()\n        {\n            try\n            {\n                var url = \"https://jsonplaceholder.typicode.com/todos\"; //Set your REST API url here\n\n                //Sends request to retrieve data from the web service for the specified Uri\n                var response = await httpClient.GetAsync(url);\n                using (var stream = await response.Content.ReadAsStreamAsync()) //Reads data as stream\n                {\n                    //Gets the path to the specified folder\n                    var localFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);\n\n                    var newpath = Path.Combine(localFolder, \"data.json\"); // Combine path with the file name\n\n                    var fileInfo = new FileInfo(newpath);\n\n                    //Creates a write-only file stream\n                    using (var fileStream = fileInfo.OpenWrite())\n                    {\n                        await stream.CopyToAsync(fileStream); //Reads data from the current stream and write to destination stream (fileStream)\n                    }\n                }\n            }\n            catch (OperationCanceledException e)\n            {\n                System.Diagnostics.Debug.WriteLine(@\"ERROR {0}\", e.Message);\n                return false;\n            }\n            catch (Exception e)\n            {\n                System.Diagnostics.Debug.WriteLine(@\"ERROR {0}\", e.Message);\n                return false;\n            }\n            return true;\n        }\n    }\n}\n```\n\n**C#**\n\nRead data from local file and set it to collection.\n\n``` c#\nnamespace ListViewXamarin\n{\n    public class ListViewModel : INotifyPropertyChanged\n    {\n        private dynamic items;\n        private bool isDownloaded;\n\n        public dynamic Items\n        {\n            get { return items; }\n            set\n            {\n                items = value;\n                OnPropertyChanged(\"Items\");\n            }\n        }\n        public DataServices DataService { get; set; }\n\n        public ListViewModel()\n        {\n            DataService = new DataServices();\n            GetDataAsync();\n        }\n\n        private async void GetDataAsync()\n        {\n            isDownloaded = await DataService.DownloadJsonAsync();\n            if (isDownloaded)\n            {\n                var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);\n                var fileText = File.ReadAllText(Path.Combine(localFolder, \"data.json\"));\n                //Read data from the local file path and set it to the collection bound to the ListView.\n                Items = JsonConvert.DeserializeObject\u003cdynamic\u003e(fileText);\n            }\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fjson-online-data-listview-xamarin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyncfusionexamples%2Fjson-online-data-listview-xamarin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fjson-online-data-listview-xamarin/lists"}