Problems with Json Serialize Dictionary

后端 未结 5 2487
自闭症患者
自闭症患者 2021-02-19 16:55

whenever i try to serialize the dictionary i get the exception:

System.ArgumentException: Type 
\'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializ         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-19 17:23

    I think that you are having trouble because TestEnum is declared as a private enum. Try marking it as a public enum. The serializer needs to be able to find your enum via reflection in order to serialize it.

    Also according to the Docs, the enums must have integer values. So you might want to write:

    public enum TestEnum { A = 1, B = 2, C =3 }
    

    Also, the docs say that this enum will just get mapped to its corresponding integer value during the serialization. So depending on what you are doing on the other end, Strings might be more expressive and easier to work with.

提交回复
热议问题