Generic WCF JSON Deserialization

后端 未结 5 1201
野的像风
野的像风 2020-12-05 11:33

I am a bit new to WCF and will try to clearly describe what I am trying to do.

I have a WCF webservice that uses JSON requests. I am doing fine sending/receiving JS

5条回答
  •  时光说笑
    2020-12-05 12:09

    Here's an alternative way to read json into dictionary:

    [DataContract]
    public class Contract
        {
        [DataMember]
        public JsonDictionary Registration { get; set; }
        }
    
    [Serializable]
    public class JsonDictionary : ISerializable
        {
        private Dictionary m_entries;
    
        public JsonDictionary()
            {
            m_entries = new Dictionary();
            }
    
        public IEnumerable> Entries
            {
            get { return m_entries; }
            }
    
        protected JsonDictionary(SerializationInfo info, StreamingContext context)
            {
            m_entries = new Dictionary();
            foreach (var entry in info)
                {
                m_entries.Add(entry.Name, entry.Value);
                }
            }
    
        public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
            foreach (var entry in m_entries)
                {
                info.AddValue(entry.Key, entry.Value);
                }
            }
        }
    

提交回复
热议问题