本文实例讲述了jQuery购物车插件jsorder用法。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"/> <title></title> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.9.1.min.js"><%@ WebHandler Language="C#" Class="ShoppingCar" %> using System; using System.Web; using System.Data; using System.Web.Script.Serialization; using System.Collections.Generic; using System.Collections; using System.IO; public class ShoppingCar : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; StreamReader reader = new StreamReader(context.Request.InputStream); string jsonString = HttpUtility.UrlDecode(reader.ReadToEnd()); if (MSCL.Until.IsNullOrDBNull(jsonString)) { context.Response.Write("error"); } else { jsonString = "{\"goods\": [" + jsonString + "]}"; DataSet ds = JsonToDataSet(jsonString); //获取的购物车商品列表 context.Response.Write("ok"); } context.Response.End(); } #region 解析Json成DataTable /// <summary> /// 解析Json成DataTable /// </summary> /// <param name="Json">Json字符串</param> /// <returns></returns> public static DataSet JsonToDataSet(string Json) { try { DataSet ds = new DataSet(); DataTable dt = new DataTable("shoppingcar"); JavaScriptSerializer JSS = new JavaScriptSerializer(); object obj = JSS.DeserializeObject(Json); Dictionary<string, object> datajson = (Dictionary<string, object>)obj; foreach (var item in datajson) { object[] rows = (object[])item.Value; foreach (var row in rows) { Dictionary<string, object> valneed = (Dictionary<string, object>)row; foreach (var needrow in valneed.Values) { #region Dictionary<string, object> val = (Dictionary<string, object>)needrow; DataRow dr = dt.NewRow(); foreach (KeyValuePair<string, object> sss in val) { if (!dt.Columns.Contains(sss.Key)) { dt.Columns.Add(sss.Key.ToString()); dr[sss.Key] = sss.Value; } else dr[sss.Key] = sss.Value; } dt.Rows.Add(dr); #endregion } } } ds.Tables.Add(dt); return ds; } catch { return null; } } #endregion public bool IsReusable { get { return false; } } }<!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>读取本地购物车Cookie</title> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.9.1.min.js">更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“jQuery购物车插件jsorder用法(支持后台处理程序直接转换成DataTable处理)”评论...