该DataContractJsonSerializer不能正确序列化词典。
而JavaScriptSerializer连载词典作为 {ABC:某某,高清:42}
例如,
在DataContractJsonSerializer给 [{关键:ABC,值:XYZ},{关键:高清,值:42}]
代替。
这的确是有问题,我想知道我怎么能在我的WCF服务正确序列化Dictionary对象。我找的,将至少需要努力量的解决方案。
REF:http://msdn.microsoft.com/en-us/library/bb412170.aspx
这是我最后用在WCF正确serilize词典解决办法:http://social.msdn.microsoft.com/forums/en-US/wcf/thread/765f1569-0422-4471-8ec2-1d03b2026771
解决方案 无功序列化=新DataContractJsonSerializer(typeOfObj,新DataContractJsonSerializerSettings()
{
UseSimpleDictionaryFormat =真
});
The DataContractJsonSerializer is not able to serialize Dictionaries properly.
Whereas JavaScriptSerializer serializes Dictionaries as {"abc":"xyz","def":42}
for example,
the DataContractJsonSerializer gives [{"Key":"abc","Value":"xyz"},{"Key":"def","Value":42}]
instead.
This is really problematic and I want to know how can I serialize Dictionary objects correctly in my WCF service. I am looking for a solution that would require least amount of effort.
ref: http://msdn.microsoft.com/en-us/library/bb412170.aspx
This is the workaround I finally used to serilize dictionaries properly in WCF: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/765f1569-0422-4471-8ec2-1d03b2026771
解决方案var serializer = new DataContractJsonSerializer(typeOfObj, new DataContractJsonSerializerSettings()
{
UseSimpleDictionaryFormat = true
});