【发布时间】:2011-12-03 23:59:58
【问题描述】:
我有一个类似这样的 WCF 端点:
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")]
Stream DoWork(Dictionary<string, string> items);
为了将任何内容传递给我的服务,我必须像这样构造我的 JSON:
{"items":[{"Key":"random1","Value":"value1"}, {"Key":"random2","Value":"value2"}]}
我真正希望它看起来像这样:
{"items":{"random1":"value1","random2":"value2"}}
有没有办法做到这一点?
【问题讨论】:
-
检查stackoverflow.com/questions/7590088/…>
-
@NewBeeee - 这并不容易。您想设置 DataContractJsonSerializerSettings.UseSimpleDictionaryFormat 但它从未暴露,因此您需要更换整个序列化程序。请参阅stackoverflow.com/questions/6792785 或stackoverflow.com/questions/11003016。可能还需要stackoverflow.com/questions/33554997。
-
@NewBeeee - 事实上我认为stackoverflow.com/questions/6792785/… 是重复的。
标签: c# json wcf serialization