I am building a web api method in c# which should be capable of accepting string value or Complex type like Objects. For that i have written below sample snippet which seems to be working with Content-Type: 'application/json'.
public IHttpActionResult jsonstring([FromBody] dynamic json)
{
string type = Convert.ToString(HttpContext.Current.Request.Headers["type"]);
if (type == "json")
{
List<CDump> jsondump = json.ToObject<List<CDump>>();
}
else if (type == "string")
{
//Decompress json string
List<CDump> jsondump = JsonConvert.DeserializeObject<List<CDump>>(json);
}
else if (type == "pipe")
{
//string str = File.ReadAllText(@"C:\Users\RJhaveri\Desktop\1t-c300420.txt");
string[] alllines = json.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
}
return Ok();
}
To get any type of data whether complex objects or string type of data, i am using dynamic keyword. What i wonder is, will i have any impact in implementing or making request to this api?
Thanks in advance!
>();`.