How to bind JSON data in Xamarin DataForm?
You can bind the data from JSON (JavaScript Object Notation) in Xamarin DataForms.
C#
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; } }
Convert String type into DateTime type when adding items to the local collection from JSON data model, since JSON does not support DateTime type.
C#
Create data for the data model.
//// Add data for JSON data model private string JsonData = "[{\"UserName\": \"Chan\",\"UserGender\": \"Male\",\"UserMail\": \"chan@yyy.com\",\"UserCountry\": \"Japan\", \"UserBirthDate\": \"05/01/1996\"}]";
C#
Deserialize the JSON data as list of JSON data model.
List<JSONData> jsonDataCollection = JsonConvert.DeserializeObject<List<JSONData>>(JsonData);
C#
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
Conclusion
I hope you enjoyed learning how to bind JSON data in Xamarin Data Form.
You can refer to our Xamarin DataForms feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Xamarin dataForms example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!