我将Xamarin.IOS项目移植到它的Unified版本,并且我使用ServiceStack.Text包遇到问题。 我已经使用NuGet将它添加到项目中。
所以我在Xamarin上创建了一个新的空项目来测试它并且问题保持不变,所以,这是测试项目代码:
using UIKit;
using ServiceStack.Text;
using System;
namespace ServiceStackTester
{
public class Test {
public string Field1 { get; set;}
public string Field2 { get; set;}
}
public class Application
{
// This is the main entry point of the application.
static void Main (string[] args)
{
Test t = JsonSerializer.DeserializeFromString<Test>("{Field1:\"A\",Field2:\"B\"}");
Console.WriteLine (t.Field1);
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}
JsonSerializer.DeserializeFromString导致此错误:
System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Json.JsonReader`1
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Json.JsonReader
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Common.JsReader`1
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.Common.JsWriter
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.Text.JsConfig
---> System.Exception: An exception was thrown by the type initializer for ServiceStack.LicenseUtils
---> System.Exception: Object reference not set to an instance of an object
at ServiceStack.LicenseUtils..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.JsConfig..cctor () [0x00051] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Common.JsWriter..cctor () [0x0005a] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Common.JsReader`1[ServiceStack.Text.Json.JsonTypeSerializer]..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Json.JsonReader..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.Json.JsonReader`1[ServiceStackTester.Test]..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at ServiceStack.Text.JsonSerializer.DeserializeFromString[Test] (System.String value) [0x00012] in <filename unknown>:0
at ServiceStackTester.Application.Main (System.String[] args) [0x00006] in /Users/daniele/Projects/ServiceStackTester/ServiceStackTester/Main.cs:17
这是许可问题还是我错过了什么? 谢谢, 丹尼尔
答案 0 :(得分:1)
我认为你错过了字段名称旁边的双引号。
“{\” 字段1 \ “:\” A \ “\ ”字段2 \“:\ ”B \“}”
会做的伎俩。