Ich habe eine einfache Frage: Ist es möglich, F # Map type von json zu analysieren? Denn wenn ich es versuche (mit F# Map<string, string>
), ist es einfach zu serialisieren und es sieht so aus, wie es sein muss, aber wenn ich versuche es zu deserialisieren, gibt es eine Ausnahme.Deserializing F # Map von Json.Net
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
Und es ist Deserialisieren von klassisch:
Map.ofList [ ("1", "one"); ("2", "two"); ("3", "three") ]
Die resultierende JSON sieht aus wie C# Wörterbuch
{
"1": "one",
"2": "two",
"3": "three"
}
Es wird ohne Einstellungen Serialisierung (Nur Vertiefung). Also ist es möglich, dies zu serialisieren, oder gibt es eine Workaround?
Vielen Dank für Antwort
Ich stelle mir vor, dass es ein signifikantes Problem gibt, da die F # -Karte unveränderlich ist. –
https://gist.github.com/mausch/10022178 –