Articles in this section
Category / Section

How to Bind JSON data to .NET MAUI DataForm (SfDataForm)?

The Syncfusion® .NET MAUI DataForm (SfDataForm) allows you to bind data from JSON (JavaScript Object Notation) seamlessly. Follow this guide to bind JSON data effectively in your application.

 

Create a model class for the JSON data.

 

C#

public class JSONDataModel
{
    public string EmployeeName { get; set; }
    public string EmployeeDepartment { get; set; }
    public string EmployeeRole { get; set;}
    public string EmployeeBranch { get; set;}
    public string EmployeeCity { get; set;}
}

 

Store your JSON data as a string.

 

C#

private string JSONDataModel =
  "[{\"EmployeeName\": \"Robert\",\"EmployeeDepartment\": \"Development\",\"EmployeeRole\": \"Junior Developer\",\"EmployeeBranch\": \"Electronic City\", \"EmployeeCity\": \"Banglore\"}]";

 

Convert the JSON string into a collection of JSON data models using deserialization.

 

C#

List<JSONDataModel> jsonDatas = JsonSerializer.Deserialize<List<JSONDataModel>>(JSONDataModel);

 

Load the data into the DataFormModel by assigning the properties from the JSON data.

 

C#

foreach (var data in jsonDatas)
{
    this.DataFormModel.Name = data.EmployeeName;
    this.DataFormModel.Department = data.EmployeeDepartment;
    this.DataFormModel.Role = data.EmployeeRole;
    this.DataFormModel.Branch = data.EmployeeBranch;
    this.DataFormModel.City = data.EmployeeCity;
}

 

Download the complete sample on GitHub

 

Output:

 

Bind the JSON data to .NET MAUI DataForm

 

Conclusion:

 

I hope you enjoyed learning how to bind the JSON data to the .NET MAUI DataForm (SfDataForm).

 

Refer to our .NET MAUI DataForm feature tour page for its other groundbreaking feature representations. You can also explore our .NET MAUI DataForm documentation to understand how to present and manipulate data.

 

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataForm and other .NET MAUI components.

 

Please let us know in the following comment section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

 



 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied