Deserializing Multidimensional array from JSON with ServiceStack fails

ぐ巨炮叔叔 提交于 2019-12-12 03:22:10

问题


I have an object with a single double[,] property, which was serialized using ServiceStack ToJson() method as follows:

{"xy":[[-2.9774,-2.0682],[-1.1378,2.7118]]}

However I cannot deserialize it back to my object type (Parameters) using "abovestring".FromJson<Parameters>() as it throws the following exception:

System.Runtime.Serialization.SerializationException: Failed to set property 'xy' with '[[-2.9774,-2.0682],[-1.1378,2.7118]]' ---> System.FormatException: Input string was not in a correct format.
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at ServiceStack.Text.Common.DeserializeBuiltin`1.<GetParseFn>b__a(String value)
   at ServiceStack.Text.Common.JsReader`1.<>c__DisplayClassa`1.<GetCoreParseFn>b__7(String value)
   at ServiceStack.Text.Common.DeserializeArrayWithElements`2.ParseGenericArray(String value, ParseStringDelegate elementParseFn)
   at ServiceStack.Text.Common.DeserializeArray`2.<>c__DisplayClass3.<GetParseFn>b__0(String value)
   at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(TypeConfig typeConfig, String strType, EmptyCtorDelegate ctorFn, Dictionary`2 typeAccessorMap)
   --- End of inner exception stack trace ---
   at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(TypeConfig typeConfig, String strType, EmptyCtorDelegate ctorFn, Dictionary`2 typeAccessorMap)
   at ServiceStack.Text.Common.DeserializeType`1.<>c__DisplayClass3.<GetParseMethod>b__1(String value)
   at ServiceStack.Text.Json.JsonReader`1.Parse(String value)
   at ServiceStack.Text.JsonSerializer.DeserializeFromString[T](String value)
   at ServiceStack.StringExtensions.FromJson[T](String json)

The target Parameters class is:

public class Parameters {
   public double[,] xy { get; set; }
}

If I change the property type to double[][] it works, but then I don't have roundtrip capabilities. It seems like ServiceStack is unable to deserialize to a multidimensional array ([,]) even though it should be able to see that this is the property's type.

It very much looks like an implementation bug, but it seems rather surprising given how basic this scenario is. Am I missing something?

来源:https://stackoverflow.com/questions/32903830/deserializing-multidimensional-array-from-json-with-servicestack-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!