How to implement custom JSON serialization from ASP.NET web service?

后端 未结 5 681
灰色年华
灰色年华 2020-12-23 23:23

What options are there for serialization when returning instances of custom classes from a WebService?

We have some classes with a number of child collection class p

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 23:57

    I know this thread has been quiet for a while, but I thought I'd offer that if you override the SupportedTypes property of JavaScriptConverter in you custom converter, you can add the types that should use the converter. This could go into a config file if necessary. That way you wouldn't need a custom converter for each class.

    I tried to create a generic converter but couldn't figure out how to identify it in the web.config. Would love to find out if anyone else has managed it.

    I got the idea when trying to solve the above issue and stumbled on Nick Berardi's "Creating a more accurate JSON .NET Serializer" (google it).

    Worked for me:)

    Thanks to all.

提交回复
热议问题