我有一个简单的问题:是否可能从json解析F# Map类型?因为当我尝试这样做(使用
生成的JSON看起来像C#字典。
它是在没有设置的情况下进行序列化的(仅缩进)。那么是否可能对其进行序列化,或者是否有一些有效的解决方法?
谢谢回答。
F# Map<string, string>
),它很容易序列化并且看起来应该是正确的,但是当我尝试反序列化时,它会抛出异常。Newtonsoft.Json.JsonSerializationException: Unable to find a default constructor to use for type Microsoft.FSharp.Collections.FSharpMap`2[System.Int32,System.String]. Path '1', line 2, position 7.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewDictionary (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, System.Boolean& createdFromNonDefaultConstructor) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0
而且它正在从经典模式反序列化:
Map.ofList [ ("1", "one"); ("2", "two"); ("3", "three") ]
生成的JSON看起来像C#字典。
{
"1": "one",
"2": "two",
"3": "three"
}
它是在没有设置的情况下进行序列化的(仅缩进)。那么是否可能对其进行序列化,或者是否有一些有效的解决方法?
谢谢回答。