1 c# constructor json.net xamarin.ios xamarin
我知道以前曾问过这个问题,但找不到解决这个问题的答案。
我正在向返回json的Web服务发出请求,然后使用json.net将json保存为列表中的对象。
List<myclass> result;
var request = new RestRequest(url, Method.POST);
//Set the parameters of the request
//[...]
IRestResponse response = client.Execute(request)
Console.WriteLine(response.Content);
//response.Content = [{"nomPrecio":"string","nomPrecioEN":"string","IDrangoPrecio":0,"IDPoblacionMv":0,"NumOfertas":0,"NumOVotaciones":0,"Imagen":"anUrl"}]
//Everything works fine until here, and I can see the json is being received OK, but then...
result = JsonConvert.DeserializeObject<List<myclass>>(response.Content);
Run Code Online (Sandbox Code Playgroud)
然后控制台显示以下消息:
休息例外:无法找到用于类型mynamespace.myclass的构造函数。一个类应该具有一个默认构造函数,一个带有参数的构造函数或一个标有JsonConstructor属性的构造函数。路径“ [0] .nomPrecio”,第1行,位置14。
namespace mynamespace
{
public class myclass
{
public myclass()
{
}
public myclass(string nomPrecio, string nomPrecioEN, int IDrangoPrecio, int IDPoblacionMv, int NumOfertas, int NumOVotaciones, string Imagen)
{
this.nomPrecio = nomPrecio;
this.nomPrecioEN = nomPrecioEN;
this.IDrangoPrecio = IDrangoPrecio;
this.IDPoblacionMv = IDPoblacionMv;
this.NumOfertas = NumOfertas;
this.NumOVotaciones = NumOVotaciones;
this.Imagen = Imagen;
}
public string nomPrecio { get; set; }
public string nomPrecioEN { get; set; }
public int IDrangoPrecio { get; set; }
public int IDPoblacionMv { get; set; }
public int NumOfertas { get; set; }
public int NumOVotaciones { get; set; }
public string Imagen { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
更奇怪的是,我对应用程序中的其他类进行了相同的设置,没有人返回此错误,所有这些都起作用。
我尝试了很多类似“ json2csharp”的方法,但是没有任何效果。
关于我可能做错什么的任何提示?谢谢
一些链接器问题mb?尝试为您的班级添加
[Preserve(AllMembers = true)]
Run Code Online (Sandbox Code Playgroud)
将链接器设置为“ SDK和用户程序集”时,可能会发生这种情况
| 归档时间: |
|
| 查看次数: |
1099 次 |
| 最近记录: |