json转换为实体类

        public List<COB_BurnInPostTest> JsonToModels(string JsonData)
        {

            List<COB_BurnInPostTest> jobInfoList = new List<COB_BurnInPostTest> { };
            try
            {
                var obj = JsonConvert.DeserializeObject(JsonData);

                if (obj is JArray)   //判断是否为Json数组
                {
                    jobInfoList = JsonConvert.DeserializeObject<List<COB_BurnInPostTest>>(JsonData);       //json数组转为对象
                }
                else
                {
                    COB_BurnInPostTest jobInfoList1 = JsonConvert.DeserializeObject<COB_BurnInPostTest>(JsonData);   //json数据转为实体类
                    jobInfoList.Add(jobInfoList1);
                }

            }
            catch (Exception ex)
            {

            }
            return jobInfoList;
        }

 

posted @ 2021-02-02 10:46  越吃越瘦  阅读(796)  评论(0编辑  收藏  举报