0

I am new on C# and also not hands on json. I want to deserialization this json data into C# objects but don't know how to deal with these guids "ae7da5d6-4024-4f7d-9221-5d2298afe650": {} in "menus" and "categories". Your help will be appreciate.

{
"menuData": {
    "menus": {
        "ae7da5d6-4024-4f7d-9221-5d2298afe650": {
            "name": "POSIGENT-DEV",
            "categoryIds": ["e6860d33-8626-4ef0-0358-08d7df7bade0"],
            "fulfillmentModes": ["DELIVERY", "DINE_IN", "PICK_UP"],
            "id": "ae7da5d6-4024-4f7d-9221-5d2298afe650",
            "hoursData": {
                "timeZone": "GMT",
                "regularHours": [],
                "specialHours": []
            }
        },
        "categories": {

            "e6860d33-8626-4ef0-0358-08d7df7bade0": {
                "name": "Soup",
                "description": "",
                "itemIds": ["c30bfa7f-042f-4297-e46a-08d7df94661c"],
                "id": "e6860d33-8626-4ef0-0358-08d7df7bade0"
            }
        }}}}

and these are my objects:

 public class Menudata
{
    public Menus? Menus { get; set; }
    public List<Category> Categories { get; set; }
 }
public class Menus
{
    public string? Id { get; set; }
    public string? Name { get; set; }
    public string? Discription { get; set; }
    public List<Category> CategoryIds { get; set; }
    public FullfillmentMode FulfillmentModes { get; set; }
    public List<Hoursdata> HoursData { get; set; }
}
public class Category
{
    public string? Id { get; set; }
    public string? Name { get; set; }
    public string? Discription { get; set; }
    public List<Items> ItemId { get; set; }
}
  • It is never a good idea to send the `json` with property names as values. Finalize a skeleton of `json`. Decide all the properties, and submit only those properties. – Jamshaid K. Mar 10 '22 at 14:34
  • 1
    Use `Dictionary` where appropriate (or `Dictionary`). – Guru Stron Mar 10 '22 at 14:34
  • menuData? weatherForecast = JsonSerializer.Deserialize(jsonString); include Menus and Category as partial clasess – user123456 Mar 10 '22 at 14:35

0 Answers0