Replace WCF default JSON serialization

前端 未结 2 462
梦谈多话
梦谈多话 2020-11-28 14:46

Is it possible to replace the default JSON serialization of WCF (I\'m currently testing with the webHttp behaviour), and passing application/json a

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 15:13

    Consider creating classes corresponding to your JSON object structure. In that case you don't have to use Dictionary<> like:

    [DataContract]
    public class Customer
    {
        [DataMember(Name="name")]
        public string Name{get;set;}
    
        [DataMember(Name="id")]
        public int ID{get;set;}
    }
    

    This get serialized as:

    {"name": "name-value", "id": "id-value"}
    

    Of course, this is just an alternative to what you already have and may not be applicable.

提交回复
热议问题