我正在尝试反序列化某些Json,但出现此错误:
Unable to find a constructor to use for type MyNamespace.MyClass.
A class should either have a default constructor, one constructor
with arguments or a constructor marked with the JsonConstructor
attribute. Path 'timestamp', line 1, position 13.
这是我的课堂定义。显然,它具有默认构造函数。 此代码在我对其进行测试的控制台应用程序中工作正常,但在Xamarin.Forms应用程序中失败。
public class MyClass
{
public string timestamp { get; set; }
public List<MyOtherClass> Things { get; set; }
[JsonConstructor]
public MyClass()
{
Things = new List<MyOtherClass>();
}
}
public class MyOtherClass
{
public string Name { get; set; }
public string Status { get; set; }
[JsonIgnore]
public string RenderString { get { return Name + " : " + Status; } }
[JsonConstructor]
public MyOtherClass()
{
}
}
我想念什么?