samedi 5 octobre 2019

Convert json formatted data to c# classes with weird array

"items": [
    {
        "product": "desktop-licence",
        "quantity": 1,
        "display": "Desktop Licence",
        "sku": "DTQ-P",
        "subtotal": 46.32,
        "subtotalDisplay": "$46.32 AUD",
        "subtotalInPayoutCurrency": 30.08,
        "subtotalInPayoutCurrencyDisplay": "USD 30.08",
        "discount": 0.0,
        "discountDisplay": "$0.00 AUD",
        "discountInPayoutCurrency": 0.0,
        "discountInPayoutCurrencyDisplay": "USD 0.00",
        "fulfillments": {
            "desktop-licence_license_0": [
                {
                    "license": "\"BHFU-FK95-SQLF-JCG7-9NAY-969H-98\"",
                    "display": "License Key",
                    "type": "license"
                }
            ]
        }
    }
]

The above is an extract from a response received from my reseller - Fastspring.

I'm having difficulty with having my web api convert the fulfillments section into a c# class. I just can't figure out how the class/classes are constructed to account for the "desktop-licence_license_0" line. This value can be defined by me and will vary according to the product name.

In my Items class I have:

public Fulfillment[] fulfillments {get; set;}

and the Fulfillment class has properties for all the fields in the array, i.e. license, display, type.

Obviously this doesn't work.




Aucun commentaire:

Enregistrer un commentaire