Forum Xamarin.Forms

Dynamic MVVM binding from JSON in Xamarin.Forms

My Xamarin.forms application follows MVVM pattern. Model class is populated from a JSON that is returned from the service call.

For eg: Model
public class Products
private string name;
private string productId;
private string subCategory;
private string category;
private bool inStock;
private string price;
private string description;
private Specification specification;

"products": [
"productId": "PRO-75b14ce9-722b-49be-8c3a-b07d270eb0aa",
"name": "Colgate Max Fresh",
"category": "Toothpaste",
"subCategory": "Max Fresh",
"price": 27,
"description": "Maximum Freshness",
"inStock": true,
"specification": {
"weight": "50g",
"width": "25mm",
"height": "60mm"
}, ................

The Xaml has also given same binding.

Now I need to have dynamic json to be bound. My service call may return different JSON format each time(with random keys). Is it possible to do it?

Thank you in advance.


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    In the end, its an array of 2 strings...
    If you don't know what you're getting in advance you'll have to do something more generic.

    One thought:
    You could probably use a ListView...
    The ItemTemplate could be a couple Label. The first binded to the first string, the second to the second string.

Sign In or Register to comment.