服务端
string[] fields = dto.fields.Split(','); var resluts=new List<dynamic>();
//只取前端使用的字段
foreach (var item in data) { var obj = new System.Dynamic.ExpandoObject() as IDictionary<string, Object>; foreach (var field in fields) { obj.Add(field, item.GetType().GetProperty(field).GetValue(item)); } resluts.Add(obj); } //转为无标记数组 var resultarr=new List<dynamic>(); resultarr.Add(fields); foreach (var field in fields) { var fielsarr=new List<dynamic>(); foreach (var item in resluts) { fielsarr.Add(((IDictionary<string, Object>)item)[field]); } resultarr.Add(fielsarr); }
网页端
//无标记数组转为json var tojson=[] for (var i = 0; i < requestdata[1].length; i++) { var jobj = {}; for (var p = 0; p < requestdata[0].length; p++) { jobj[requestdata[0][p]] = requestdata[p+1][i]; } tojson.push(jobj); }
标签:field,fields,Add,item,JSON,foreach,数组,var,数据压缩 From: https://www.cnblogs.com/ggtc/p/17622849.html