Rixant
Rixant

Reputation: 31

How to create this schema like model in c#?

I want to create a schema output using the c# model. Example Schema


Food:[["burger", "french fries", "nuggets"], "status": "delivered"]

Model:


Public class Food
{
public List<item> items {get; set;}
}

public class item
{
public List<string> food_item {get; set;}

public string status {get; set;}
}

Upvotes: 0

Views: 201

Answers (1)

Krishna Varma
Krishna Varma

Reputation: 4260

The proper json should look like below

"Food":[{"food_item":["burger", "french fries", "nuggets"], "status": "delivered"}]

And the model (use https://json2csharp.com/ to validate and convert your json to model)

public class Food
{
    public List<string> food_item { get; set; }
    public string status { get; set; }
}

public class Root
{
    public List<Food> Food { get; set; }
}

Deserialize using below code

Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 

Upvotes: 1

Related Questions