我收到一条错误消息“无法将字符串转换为整数:3.500。json 转换为对象时的路径“数量” 。
json:
{"ProductCalcKey":"xxx","PaperType":"1","Quantity":"3.500"}
目的:
public class UnitPrice
{
public int UnitPriceId { get; set; }
public int QuantityMin { get; set; }
public int QuantityMax { get; set; }
public decimal Price { get; set; }
public string ProductCalcKey { get; set; }
public PaperType? PaperType { get; set; }
public int Quantity { get; set; }
}
我正在使用以下方法。
protected object FromJsonToObject(Type t)
{
Context.Request.InputStream.Position = 0;
string json;
using (var reader = new StreamReader(Context.Request.InputStream))
{
json = reader.ReadToEnd();
}
// todo: string to integer such as '222.222.222'
return JsonConvert.DeserializeObject(json, t, new IsoDateTimeConverter());
}
如何在不接触 jsontext 的情况下解决这个问题?