替换 WCF 默认的 JSON 序列化 [英] Replace WCF default JSON serialization

查看:34
本文介绍了替换 WCF 默认的 JSON 序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以替换 WCF 的默认 JSON 序列化(我目前正在使用 webHttp 行为进行测试),并将 application/json 作为 MIME 类型传递.特别是,我不喜欢默认情况下每个属性都是一个键/值对,例如:

Is it possible to replace the default JSON serialization of WCF (I'm currently testing with the webHttp behaviour), and passing application/json as the MIME type. In particular, I don't like that by default every property is a key/value pair like:

{"Key":"PropertyName", "Value":"PropertyValue"}

我仅将此服务用于支持 JSON 的端点(使用 jQuery + WCF 请求数据).

I'm using the service only for JSON-enabled endpoints (requesting data with jQuery + WCF).

推荐答案

您可以使用消息格式化程序来更改用于处理 JSON 的序列化程序.https://docs.microsoft.com/en-us/archive/blogs/carlosfigueira/wcf-extensibility-message-formatters 展示了如何将默认序列化器 (DataContractJsonSerializer) 更改为另一个 (JSON.NET) 的示例.

You can use a message formatter to change the serializer used to deal with JSON. The post at https://docs.microsoft.com/en-us/archive/blogs/carlosfigueira/wcf-extensibility-message-formatters shows an example on how to change the default serializer (DataContractJsonSerializer) to another one (JSON.NET).

这篇关于替换 WCF 默认的 JSON 序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆