首页 > Windows开发 > 详细

web api使用JObject接收时,报“无法创建抽象类”错误

时间:2019-04-03 23:39:40      阅读:204      评论:0      收藏:0      [点我收藏+]

https://bbs.csdn.net/topics/391952288

在下列函数中增加  ModelBinders.Binders.Add(typeof(JObject), new JObjectModelBinder());

public static void RegisterRoutes(RouteCollection routes)
{
     ModelBinders.Binders.Add(typeof(JObject), new JObjectModelBinder());
}

public class JObjectModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var stream = controllerContext.RequestContext.HttpContext.Request.InputStream;
            stream.Seek(0, SeekOrigin.Begin);
            string json = new StreamReader(stream).ReadToEnd();
            return JsonConvert.DeserializeObject<dynamic>(json);
        }
    }

 

web api使用JObject接收时,报“无法创建抽象类”错误

原文:https://www.cnblogs.com/hwubin5/p/10652392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!