User475983607 posted
You're not following standard practises.
First create a C# class that has the expected format. All you have to do is copy the expected JSON format then paste it into a cs file in Visual Studio. Click Edit -> Paste Special -> Paste as JSON class. You'll need to fix the LogoUrl
case as you have a typo in the JSON file.
public class Rootobject
{
public Suggestion[] suggestions { get; set; }
}
public class Suggestion
{
public string value { get; set; }
public Data data { get; set; }
}
public class Data
{
public string logoUrl { get; set; }
public string RouteUrl { get; set; }
public string Discount { get; set; }
}
Next, fill the class using your data access layer. The common approach is using an EF project query. I can't see your DB schema so I can't provide accurate code to populate the class. You'll need to figure that bit out on your own.
Once you have the class populated simply return the class just like any C# method. The following is an example uses Web API. I hardcoded the values to simulate fill the class with data from the data access layer.
public Rootobject Get()
{
Rootobject root = new Rootobject()
{
suggestions = new Suggestion[]
{
new Suggestion()
{
value = "Dell",
data = new Data()
{
Discount = "1%",
logoUrl = "logo.png",
RouteUrl = "some path"
}
},
new Suggestion()
{
value = "Walmart",
data = new Data()
{
Discount = "5%",
logoUrl = "logo.png",
RouteUrl = "some path"
}
}
}
};
return root;
}
I recommend that you go through a few of the Getting Started tutorials located on this site from the "Learn" link above. You'll need to pick the technology you're using.
https://www.asp.net/web-api