public class RootobjectTest
{
public int timestamp { get; set; }
public string Base { get; set; }
public Rates rates { get; set; }
}
public class Rates
{
public float AED { get; set; }
public float AFN { get; set; }
public float ALL { get; set; }
public float AMD { get; set; }
public float YER { get; set; }
public float ZAR { get; set; }
public float ZMK { get; set; }
public float ZMW { get; set; }
public float ZWL { get; set; }
}
var jsonData = @"{ ""timestamp"": 1370340068, ""base"": ""USD"", ""rates"": {
""AED"":
3.672958, ""AFN"": 54.154801, ""ALL"": 107.66425, ""AMD"": 419.62875,
""YER"": 214.964253, ""ZAR"": 9.813218, ""ZMK"": 5227.108333, ""ZMW"": 5.344453,
""ZWL"": 322.387247 }}";
var currencyRates = JsonConvert.DeserializeObject<RootobjectTest>(jsonData);
一切都很好,并且运行良好。但如果我改变
public int timestamp { get; set; }
至
public bool timestamp { get; set; }
我没有收到任何错误。Json.Net 解析时间戳的 int 值并将其转换为 bool。有没有优雅而简单的方法来禁止这种情况?