Skip to content

This repository contains a sample on How to bind JSON data to the Syncfusion Xamarin.Forms DataForm (SfDataForm)?

Notifications You must be signed in to change notification settings

SyncfusionExamples/json-binding-dataform-xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to bind JSON data to Xamarin.Forms DataForm (SfDataForm) ?

You can bind the data from JSON (JavaScript Object Notation) in Xamarin.Forms SfDataForm.

You can refer the following article.

https://www.syncfusion.com/kb/11310/how-to-bind-json-data-to-xamarin-forms-dataform-sfdataform

Create a JSON data model.

/// <summary>   
/// Represents custom data properties.   
/// </summary> 
public class JSONData
{
       public string UserName { get; set; }
       public string UserGender { get; set; }
       public string UserMail { get; set; }
       public string UserCountry { get; set; }
}

Note: Convert String type into DateTime type when adding items to the local collection from JSON data model, since JSON does not support DateTime type.

Create data for the data model.

//// Add data for JSON data model
private string JsonData =
          "[{\"UserName\": \"Chan\",\"UserGender\": \"Male\",\"UserMail\": \"[email protected]\",\"UserCountry\": \"Japan\", \"UserBirthDate\": \"05/01/1996\"}]";

Deserialize the JSON data as list of JSON data model.

List<JSONData> jsonDataCollection = JsonConvert.DeserializeObject<List<JSONData>>(JsonData);

Load the JSON data list into the DataForm model.

foreach (var data in jsonDataCollection)
{
                this.ContactsInfo.Name = data.UserName;
                this.ContactsInfo.Gender = data.UserGender;
                this.ContactsInfo.Email = data.UserMail;
                this.ContactsInfo.Country = data.UserCountry;
                this.ContactsInfo.DateOfBirth = Convert.ToDateTime(data.UserBirthDate);
}

Output

DataFormJsonData

About

This repository contains a sample on How to bind JSON data to the Syncfusion Xamarin.Forms DataForm (SfDataForm)?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages