C# 中 DapperRow 数据解析

                            using Newtonsoft.Json;

                             List<DataColumnModel> lstColumn = new List<DataColumnModel>()
                            {
                                new DataColumnModel { ColumnName = "Name", ColumnCaption = "部门名称", ColumnType = typeof(string) },
                                new DataColumnModel { ColumnName = "Value", ColumnCaption = "小计", ColumnType = typeof(int) }
                            };
                        string json = JsonConvert.SerializeObject(data.rows); 
                        JArray jArray = (JArray)JsonConvert.DeserializeObject(json);
                        JToken jObj = (JToken)jArray[0];

                        foreach (JProperty jp in jObj)
                        {
                            string name = jp.Name;
                            if (name != "Name" && name != "OrgId" && name != "Value")
                            {
                                DataColumnModel col = new DataColumnModel();
                                col.ColumnName = name;
                                col.ColumnCaption = name;
                                col.ColumnType = typeof(int);
                                lstColumn.Add(col);
                            }
                        }

posted @ 2018-09-28 15:29  C小小  阅读(3911)  评论(0编辑  收藏  举报