【发布时间】:2015-01-14 14:26:39
【问题描述】:
我有一个 Web API 2 项目,我的 WebApiConfig 看起来像这样:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config
.MapHttpAttributeRoutes();
config
.Formatters
.JsonFormatter
.SupportedMediaTypes
.Add(new MediaTypeHeaderValue("text/html"));
}
}
这很好用,但我希望将 json 解析为“Mongo DB 样式”,以便自动获取 ObjectID 的序列化,因此我可以在模型类中的属性上使用 [BsonElement("name")] 之类的属性等等。
我环顾四周,找到了这篇文章http://odetocode.com/blogs/scott/archive/2013/09/30/custom-serialization-with-json-net-webapi-and-bsondocument.aspx,但它似乎有点过时了,我无法让它发挥作用。
我暂时卡住了,非常感谢您的帮助。
【问题讨论】:
标签: json mongodb asp.net-web-api asp.net-web-api2