我想向我的Web API发送对象的数据。该API接受一个类参数,其中属性的类型是int和string。
这是我的类:
public class deneme
{
public int ID { get; set; }
public int sayi { get; set; }
public int reqem { get; set; }
public string yazi { get; set; }
}
这是我的JSON对象:This is my JSON object:
{
"id":0,
"sayi":"9",
"reqem":8,
"yazi":"sss"
}
我希望API能够将属性"sayi"读取为整数,但由于无法这样做,它会产生错误:
The JSON value could not be converted to System.Int32. Path: $.sayi
我该如何解决这个问题?
"sayi": 9
(不带引号),或者您必须将其绑定到字符串而不是整数,并自行进行转换。没有其他选择。 - Chris Pratt