本文实例讲述了jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Ajax和getJSON获取后台普通Json数据和层级Json数据解析</title> <script src="/UploadFiles/2021-04-02/jquery-1.8.0.min.js"><%@ WebHandler Language="C#" Class="jsondata" %> using System; using System.Web; using System.Web.Script.Serialization; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; using System.Data; using Newtonsoft.Json; public class jsondata : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); string type = context.Request["type"]; if (type=="1") //普通数据 { List<Dictionary<String, String aa = new List<Dictionary<string, string(); for (int i = 0; i < 6; i++) { Dictionary<String, String> aaa = new Dictionary<string, string>(); aaa.Add("id", "no" + i); aaa.Add("name", "张三" + i); aaa.Add("age", "21"); aaa.Add("score", "1001"); aa.Add(aaa); } string json = JsonConvert.SerializeObject(aa, Formatting.Indented); context.Response.Write(json); } if (type == "3") //层级数据 { List<Student> list = new List<Student>(); for (int i = 0; i < 6; i++) { Student a = new Student(); a.id = "no" + i; a.name = "张三" + i; a.age = "21"; Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("语文","80"); dic.Add("数学", "81"); dic.Add("英语", "83"); dic.Add("生物", "89"); dic.Add("化学", "90"); dic.Add("物理", "95"); a.score = dic; list.Add(a); } string json = JsonConvert.SerializeObject(list, Formatting.Indented); context.Response.Write(json); } } public struct Student { public string id; public string name; public string age; public Dictionary<string,string> score; } public bool IsReusable { get { return false; } } }更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 明达年度发烧碟MasterSuperiorAudiophile2017[DSF]
- 翁立友.2008-恨孤单【大旗】【WAV+CUE】
- 群星.2009-Magic.Cover日粤精华3CD【环球】【WAV+CUE】
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]