。net 后台将List数据转换为json后 前台js 调用

xiaoxiao2021-02-28  126

//C#后台代码 public string ReturnType() { DataTable TypeList = ClassOrAboutBLL.Instance.Type(); List<ClassOrAboutModel> list = new List<ClassOrAboutModel>(); foreach (DataRow item in TypeList.Rows) { ClassOrAboutModel model = new ClassOrAboutModel(); model.ClassOrAboutType = item["ClassOrAbout"].ToString(); model.Type = item["Type"].ToString(); model.TypeDescibe = item["TypeDescibe"].ToString(); list.Add(model); } DataContractJsonSerializer json = new DataContractJsonSerializer(list.GetType()); string szJson = ""; using (MemoryStream stream = new MemoryStream()) { json.WriteObject(stream, list); szJson = Encoding.UTF8.GetString(stream.ToArray()); } return szJson; } function changetype(){ var Type = <%=ReturnType() %>; //Type[i].TypeDescibe //Type[i].Type }
转载请注明原文地址: https://www.6miu.com/read-36812.html

最新回复(0)