Answer the question
In order to leave comments, you need to log in
How to get the type from a variable?
Hello dear. The essence of the problem is this.
I get JSON in the method "DataCreate(string JsonData, string ObjectName)"
JsonData- the data itself
ObjectName - the name of the object into which this data needs to be deserialized.
var DataObject = oJS.Deserialize<ObjectName>(JsonData);
[HttpPost]
public JsonResult DataCreate(string JsonData, string ObjectName)
{
JavaScriptSerializer oJS = new JavaScriptSerializer();
var DataObject = oJS.Deserialize<ObjectName>(JsonData);
return Json(new { Message = "Данные добавлены"}, JsonRequestBehavior.AllowGet);
}
Answer the question
In order to leave comments, you need to log in
It's just a very big security hole if you allow an object to be mapped to any type. Sooner or later, a type will be selected that will execute / interpret the result on the property set and this hole will be exploited.
It will be safe to map to known types via switch. Or through a pre-prepared dictionary "name / type".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question