C# Serialize Dictionary to JSON

后端 未结 3 1852
没有蜡笔的小新
没有蜡笔的小新 2021-02-14 08:54

I am trying to serialize a Dictionary to JSON, and get the following exception:

new JavaScriptSerializer().Serialize(mydict)`

Ty

3条回答
  •  一个人的身影
    2021-02-14 09:37

    var dict = mapping.ToDictionary(item => item.Key.ToString(), item => item.Value.ToString());`
    

    that will convert any Dictionary to Dictionary and serialization then works.

提交回复
热议问题