F#WebAPI默认反序列化生成@符号(F# WebAPI default deserialization producing @ sign)

编程入门 行业动态 更新时间:2024-10-09 05:14:18
F#WebAPI默认反序列化生成@符号(F# WebAPI default deserialization producing @ sign)

我正在开发一个F#Web API应用程序 - https://github.com/odytrice/Dumia

当我尝试发送以下记录的数组时,

[<CLIMutable>] type Product = { ProductID : int Code : string Name : string Price : decimal ImageUrl : string } [<CLIMutable>] type Inventory = { Product: Product Quantity: int }

这是我当前的WebAPI配置

let registerWebApi (app:IAppBuilder) = let config = new HttpConfiguration() // Configure routing config.MapHttpAttributeRoutes() // Remove XML Formatter config.Formatters.Clear() let formatter = new JsonMediaTypeFormatter() formatter.UseDataContractJsonSerializer <- false config.Formatters.Add(formatter) config.Services.Replace(typeof<IHttpControllerActivator>, CompositionRoot()) app.UseWebApi(config)

我的Web API正在生成以下输出

{ Product@: { ProductID@: 1, Code@: "Bag-01", Name@: "Ladies Bag", Price@: 120, ImageUrl@: "/content/images/bag.jpg" }, Quantity@: 15 }

有没有人知道如何摆脱@符号?

I'm working on an F# Web API application - https://github.com/odytrice/Dumia

When I try to send an Array of the following records,

[<CLIMutable>] type Product = { ProductID : int Code : string Name : string Price : decimal ImageUrl : string } [<CLIMutable>] type Inventory = { Product: Product Quantity: int }

Here is my current WebAPI Configuration

let registerWebApi (app:IAppBuilder) = let config = new HttpConfiguration() // Configure routing config.MapHttpAttributeRoutes() // Remove XML Formatter config.Formatters.Clear() let formatter = new JsonMediaTypeFormatter() formatter.UseDataContractJsonSerializer <- false config.Formatters.Add(formatter) config.Services.Replace(typeof<IHttpControllerActivator>, CompositionRoot()) app.UseWebApi(config)

My Web API is producing the following output

{ Product@: { ProductID@: 1, Code@: "Bag-01", Name@: "Ladies Bag", Price@: 120, ImageUrl@: "/content/images/bag.jpg" }, Quantity@: 15 }

Does anyone have an idea how to get rid of the @ sign?

最满意答案

问题是由于WebAPI使用的默认DataContract。

我不得不改变它

config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.DefaultContractResolver()

还是更好

config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.CamelCasePropertyNamesContractResolver()

The Problem is because of the Default DataContract used by WebAPI.

I had to change it to

config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.DefaultContractResolver()

or better yet

config.Formatters .JsonFormatter .SerializerSettings .ContractResolver <- Serialization.CamelCasePropertyNamesContractResolver()

更多推荐

本文发布于:2023-08-03 18:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396190.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   序列化   WebAPI   default   sign

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!