一、dynamic使用:
从一直使用动态类型写接口 返回动态类型出现情况
1、返回接口每次不知道包含那些列(实体类解决)
2、操作的数据类型 不可知(参与数值计算-实体类解决明确类型)
Dynamic 真不适合解决
static void Main(string[] args) { string a = "{"CaseId":"dae908a9-e28d-4e3e-be78-fa8c7ce1afaa","DivisionId":"310112114","Address":"","UnitPrice":"0","TotalPrice":"0","QueryDate":"2019/7/9 8:59:39","AvgUnitPrice":"0","AvgPrice":"0","MaxPrice":"0","MinPrice":"0","MangerPrice":"0","Liveness":"1","TotalCellNumber":"0","QueryCount":"0","ReturnCode":"-1","Remark":"楼盘不可估","EndDate":"2019/01/01 0:00:00","ConstructionName":"","ConstructionAlias":"","BuildingName":"","HouseName":"","PropertyType":"","QuotationCount":"0"}"; string b = "{"CaseId":"b1a9f1ea-686c-4c95-9bc8-a23737ac715c","DivisionId":"310109014","Address":"虹口区临平北路60弄","UnitPrice":"55676","TotalPrice":"7259594","QueryDate":"2019/7/9 10:37:52","AvgUnitPrice":"55676","AvgPrice":"55676","MaxPrice":"62914","MinPrice":"46891","MangerPrice":"0.9","Liveness":"3","TotalCellNumber":"631","QueryCount":"0","ReturnCode":"1","Remark":"估价成功","EndDate":"1997/01/01 0:00:00","ConstructionName":"临平北路60弄","ConstructionAlias":"银欣花苑","BuildingName":"","HouseName":"","PropertyType":"","QuotationCount":"34"}"; dynamic aa = JsonConvert.DeserializeObject(a); dynamic bb = JsonConvert.DeserializeObject(b); var s = aa.GetType().Name;//JObject //当值是'0' 输出 UnitPrice:'0' 与UnitPrice:0 区别 得出结果: 没有区别 输出都是{0}Value对象 判断0无区分 if (aa["UnitPrice"] != 0) { Console.Write("不等于0");///判断是否输出值 } else { Console.Write("等于0"); } if (bb["UnitPrice"] != 0) { Console.Write("不等于0");///判断是否输出值 } else { Console.Write("等于0"); } } }