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

查看:364
本文介绍了替换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的序列化程序.该帖子位于 http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx 显示了有关如何将默认序列化程序(DataContractJsonSerializer)更改为另一个序列化(JSON)的示例. NET).

You can use a message formatter to change the serializer used to deal with JSON. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx shows an example on how to change the default serializer (DataContractJsonSerializer) to another one (JSON.NET).

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

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