I'm building a web service on iis + asp.net and I'm stuck with a problem about JSON serialization. When using JSON.Net or JavaScriptSerializer, a dictionary is serialized as
{
'key0':'value0',
...
'keyN':'valueN',
}
but when it goes through the "ASP deserializer", a dictionary is serialized like this
[
{Key:'key0',Value:'value0'},
...
{Key:'keyN',Value:'valueN'}
]
I'm not familiar with ASP.net web services so I'm using a readymade template for visual studio. WHen I look in the web.config I see there are defintions for endpoints and behaviours. In one of those behaviour I see there's a reference to dataContractSerializer. This seems to be the serializer that is used under the hood when deserializing.
So my questions are :
Does dataContractSerializer can be tweaked to serialize the sane way (by using a directive in the web config) ?
Can I set another Serializer (JSON.net ?) for the endpoint in the web.config ?
My method currently outputs a Dictionary I change it to return a string (which I feed with my own serialization of my dictionary). But this didn't help much because the string get escaped by the default serializer that encloses it with '"'.
Can I override this ? By writing directly to the Response and ending the response ?
Please help me, I -really- don't want to change the existing client so I need to do it server side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.