栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法分析

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法分析

本文实例讲述了jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法。分享给大家供大家参考,具体如下:

运行效果截图如下:

具体代码如下:




  Ajax和getJSON获取后台普通Json数据和层级Json数据解析
  
  


  

方式一

____________________________________

方式二

____________________________________

方式三

____________________________________

方式四

<%@ 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> aa = new List>();
      for (int i = 0; i < 6; i++)
      {
 Dictionary aaa = new Dictionary();
 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 list = new List();
      for (int i = 0; i < 6; i++)
      {
 Student a = new Student();
 a.id = "no" + i;
 a.name = "张三" + i;
 a.age = "21";
 Dictionary dic = new Dictionary();
 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 score;
  }
  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/96337.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号