string strPost = new Utils().getPost(context);
var obj = new { name = "", age = "" };
obj = JSONHelper.JsonToObject(strPost, obj);
public string getPost(HttpContext context)
{
return new StreamReader(context.Request.InputStream).ReadToEnd();
}
public static T JsonToObject<T>(string json, T anonymousTypeObject)
{
T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject);
return t;
}
好处:懒人多作怪,不用建model
注意:前台传的json格式才能被getPost读取,或者自己直接把strPost的值改成json内容