JSON parsed to Web API Post Call (Body)
{
"Name1": "Value1",
"Name2": "Value2",
"Name3": "Value3",
"Name4": "Value4"
}
Lets call this object NameValueObject
public class NameValueObject
{
public Name1 { get; set; }
public Name2 { get; set; }
public Name3 { get; set; }
public Name4 { get; set; }
}
What I would like to see is to be able to parse the json object and convert it into a list
public async Task<List<NameValueObject>> EvaluateJson ([FromBody] NameValueObject request)
{
string serializerequest = JsonConvert.SerializeObject(request);
//What do i next , I just to want to get a list of the values sent through the json object
}
2
Answers
You can get all the values of your properties in the
NameValueObject
by using Reflection and Linq like this:If you would like to get both the name of the property and the value you can create a dictionary like this:
you can create List< NameValueObject > objects
or just list of values
if you want List< NameValueObject > , you will have to create this class
or I would prefer this
or just list of values