使用 ServiceStack 反序列化字符串
Deserializing string using ServiceStack
我正在尝试使用 ServiceStack 将一个简单的 json 字符串反序列化为 Dto 对象:
public class TestDto
{
public int MyProp { get; set; }
}
var json = JsonSerializer.DeserializeFromString<TestDto>("{\"MyProp\":6}");
我得到异常:
[System.TypeInitializationException] =
{"The type initializer for 'ServiceStack.Text.Json.JsonReader`1' threw an exception."}
// With the inner exception:
"Object reference not set to an instance of an object."
// And the stack trace:
at ServiceStack.Text.Common.JsReader`1.GetCoreParseFn[T]()
at ServiceStack.Text.Common.JsReader`1.GetParseFn[T]()
at ServiceStack.Text.Json.JsonReader`1..cctor()
我正在 Visual Studio 中使用 Xamarin 在 Windows 8.1 上进行开发。 ServiceStack 代码位于一个可移植库中。目前我正在直接从单元测试中触发可移植库代码。
这是 ServiceStack 的 Nuget 包信息:
<package id="ServiceStack.Text" version="4.0.36"
targetFramework="portable-net45+win+MonoAndroid10+xamarinios10+MonoTouch10" />
知道我在这里遗漏了什么吗?
使用 PCL clients and Json Serializer is in the HelloMobile project 的文档,具体来说,您需要安装 ServiceStack.Client NuGet 包,其中包含支持平台所需的平台特定扩展您 运行 在:
PM> Install-Package ServiceStack.Client
对于 iOS,您还应该 explicitly initialize the PCL library 使用:
IosPclExportClient.Configure();
我正在尝试使用 ServiceStack 将一个简单的 json 字符串反序列化为 Dto 对象:
public class TestDto
{
public int MyProp { get; set; }
}
var json = JsonSerializer.DeserializeFromString<TestDto>("{\"MyProp\":6}");
我得到异常:
[System.TypeInitializationException] =
{"The type initializer for 'ServiceStack.Text.Json.JsonReader`1' threw an exception."}
// With the inner exception:
"Object reference not set to an instance of an object."
// And the stack trace:
at ServiceStack.Text.Common.JsReader`1.GetCoreParseFn[T]()
at ServiceStack.Text.Common.JsReader`1.GetParseFn[T]()
at ServiceStack.Text.Json.JsonReader`1..cctor()
我正在 Visual Studio 中使用 Xamarin 在 Windows 8.1 上进行开发。 ServiceStack 代码位于一个可移植库中。目前我正在直接从单元测试中触发可移植库代码。
这是 ServiceStack 的 Nuget 包信息:
<package id="ServiceStack.Text" version="4.0.36"
targetFramework="portable-net45+win+MonoAndroid10+xamarinios10+MonoTouch10" />
知道我在这里遗漏了什么吗?
使用 PCL clients and Json Serializer is in the HelloMobile project 的文档,具体来说,您需要安装 ServiceStack.Client NuGet 包,其中包含支持平台所需的平台特定扩展您 运行 在:
PM> Install-Package ServiceStack.Client
对于 iOS,您还应该 explicitly initialize the PCL library 使用:
IosPclExportClient.Configure();