欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery+ajax读取json数据并按照价格排序示例

程序员文章站 2022-04-01 09:23:15
本文实例讲述了jquery+ajax读取json数据并按照价格排序。分享给大家供大家参考,具体如下:

本文实例讲述了jquery+ajax读取json数据并按照价格排序。分享给大家供大家参考,具体如下:

<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <script src="jquery-1.9.1.js"></script>
 <script>
 $.ajax({
  url: 'data.json',//获取本地json数据,在同文件夹下
  type: "get",
  success: function(resp) {
  console.log(resp); //原始数据
  var data = resp;
  //原生javascript sort() 方法
  data.data.sort(function(good1, good2) {
   /* 用价格排序由小到大 */
   return good1.price1 > good2.price1;
  });
  console.log(data.data);//排序后的数据
  },
  error: function(resp) {
  alert("系统繁忙,请稍后再试...");
  }
 });
 </script>
</head>
<body>
</body>
</html>

json数据 data.json:

{
 "code": 0,
 "data": [{
  "id": 16,
  "title": "fiveplus棉质纯色拼接圆领连衣裙",
  "name": "fiveplus2017新品女夏装棉质纯色拼接圆领短袖连衣裙2jm2080240",
  "promotion": "促销活动",
  "size": "xxl;xl;m;s;l",
  "color": "深蓝;深绿",
  "picmini": "",
  "pic": "/upload/20170826161653_20170823141557.jpg,/upload/20170826161653_20170823141625.jpg,/upload/20170826161653_20170823141803.jpg,/upload/20170826161653_20170823141857.jpg,/upload/20170826161653_20170823141925.jpg",
  "parameter": "材质成分:棉68%聚酯纤维29.5%聚氨酯弹性纤维(氨纶)2.5%;销售渠道类型:商场同款(线上线下都销售);货号:2jm2080240;裙长:短裙;品牌:fiveplus;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:深蓝650米白010;尺码:x、s、m、l",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 399.00,
  "price2": 799.00,
  "longpic": "/upload/20170828102154_haibao (1).png",
  "score": 20,
  "createdate": "2017-08-26 14:49:09",
  "updatedate": "2017-08-26 14:49:09"
 }, {
  "id": 18,
  "title": "moco高腰拼接无袖镂空蕾丝连衣裙",
  "name": "moco高腰拼接无袖镂空蕾丝连衣裙修身a字裙子ma162skt106摩安珂",
  "promotion": null,
  "size": "s;m",
  "color": "白色;黑色",
  "picmini": "",
  "pic": "/upload/20170826161938_tb1biadofxxxxayxxxxxxxxxxxx_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826161938_tb2pweaa30kpufjsspdxxx4yxxa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_tb2uqpaastkpufjy0fhxxxqzfxa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_tb2zw4hcr0kpufjsszixxa.ovxa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_tb22u2tac0mpufjszpixxbssvxa_!!1746622942.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:聚酯纤维94.4%聚氨酯弹性纤维(氨纶)5.6%;销售渠道类型:商场同款(线上线下都销售);货号:ma162skt106;风格:街头;街头:欧美组合;形式:单件;裙长:短裙;款式:其他/other;袖长:无袖;领型:圆领;袖型:常规;腰型:高腰衣;门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:镂空勾花镂空蕾丝;品牌:mo&co./摩安珂;适用年龄:25-29周岁;年份季节:2016年夏季",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 300.00,
  "price2": 400.00,
  "longpic": null,
  "score": 20,
  "createdate": "2017-08-26 15:10:48",
  "updatedate": "2017-08-26 15:10:48"
 }, {
  "id": 20,
  "title": "cmisssixty夏装拼接露肩式牛仔连衣裙",
  "name": "cmisssixty夏装拼接露肩式牛仔连衣裙套装662dj3220000",
  "promotion": null,
  "size": "xsml",
  "color": "深蓝;红色;白色",
  "picmini": "",
  "pic": "/upload/20170826162219_tb1f80hqxxxxxc8xxxxxxxxxxxx_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826162219_tb2jpayddccl1fjszfpxxxzgpxa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_tb2nnpri5pnpufjszfkxxc4zpxa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_tb2ub4wi98mpufjszfmxxaxpvxa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_tb2zhxmi.hnpufjszfexxx0pfxa_!!1880906465.jpg_430x430q90.jpg",
  "parameter": "材质成分:棉98.4%聚氨酯弹性纤维(氨纶)1.6%;销售渠道类型:商场同款(线上线下都销售);货号:662dj3220000;裙长:中裙;品牌:misssixty;适用年龄:25-29周岁;年份季节:2016年夏季;颜色分类:深蓝f58;尺码:xs、s、m、l",
  "businessname": "测试111",
  "typename": "连衣裙",
  "businessid": 3,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 800.00,
  "price2": 1000.00,
  "longpic": "",
  "score": 30,
  "createdate": "2017-08-26 16:21:49",
  "updatedate": "2017-08-26 16:21:49"
 }, {
  "id": 45,
  "title": "雪纺连衣裙2017新款秋装七分袖气质时尚女装碎花修身连衣裙春秋",
  "name": "气质女神,春秋必备",
  "promotion": null,
  "size": "smlxl",
  "color": "白色;粉色;兰色;黑色",
  "picmini": "",
  "pic": "/upload/20170828111058_tb1vz7mqfxxxxalxvxxxxxxxxxx_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111058_tb2dtj2hw0kpufjsspdxxx4yxxa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_tb2off_hb0kpufjsszixxa.ovxa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_tb2pow1hylnpufjszfgxxbi7fxa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_tb2srulgmxjpufjsszexxaemvxa_!!729863055.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:af5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:s、m、l、xl",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 139.00,
  "price2": 259.00,
  "longpic": "",
  "score": 13,
  "createdate": "2017-08-28 11:10:41",
  "updatedate": "2017-08-28 11:10:41"
 }, {
  "id": 46,
  "title": "韩版女装2017夏季新款冰丝针织小黑裙连衣裙中裙女夏装露肩a字裙",
  "name": "新款冰丝针织小黑裙",
  "promotion": null,
  "size": "smlxl",
  "color": "黑色",
  "picmini": "",
  "pic": "/upload/20170828111250_tb1pfjspfxxxxbuxvxxxxxxxxxx_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111250_tb2ahefxxrdoufjszfzxxciipxa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_tb2cbbaeb0kpufjsszixxa.ovxa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_tb2wbcahcjjpufjy0fdxxxmofxa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_tb21gzpeb8lpufjsspaxxxjkpxa_!!2923124116.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:af5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:s、m、l、xl",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 158.00,
  "price2": 188.00,
  "longpic": "",
  "score": 15,
  "createdate": "2017-08-28 11:15:09",
  "updatedate": "2017-08-28 11:15:09"
 }, {
  "id": 47,
  "title": "吊带露背沙滩裙女夏2017新款海边度假性感波西米亚长裙显瘦连衣裙",
  "name": "吊带露背沙滩裙",
  "promotion": null,
  "size": "lsm",
  "color": "094花俏",
  "picmini": "",
  "pic": "/upload/20170828111644_tb1cbx8rvxxxxaqxvxxxxxxxxxx_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111644_tb2e5yfp0ropufjszftxxcanpxa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_tb2q0zzvnxkpufjy0fixxbuffxa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_tb2qxsqvsbjpufjssplxxa5mvxa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_tb2twgokuttmefjszfoxxativxa_!!1969979810.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:af5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:s、m、l、xl",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 148.00,
  "price2": 248.00,
  "longpic": "",
  "score": 14,
  "createdate": "2017-08-28 11:17:44",
  "updatedate": "2017-08-28 11:17:44"
 }, {
  "id": 49,
  "title": "palglg裙子女2017新款夏季女装韩版宽松挂脖a字网纱连衣裙3353",
  "name": "精致绣花宽松显瘦减龄蝴蝶结系带",
  "promotion": null,
  "size": "sml",
  "color": "藕粉色;白色;浅绿色",
  "picmini": "",
  "pic": "/upload/20170828111920_tb1htylx0.ll1jjszfexxcvmxxa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111920_tb2baczubvkpufjsspcxxbsmvxa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_tb2cnk7gh0kpufjy0fjxxcbbvxa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_tb2rm4utmxlpufjy0foxxa.lxxa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_tb2xlw0hyxmpufjszjixxxauvxa_!!2456840063.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:af5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:s、m、l、xl",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 169.00,
  "price2": 369.00,
  "longpic": "",
  "score": 16,
  "createdate": "2017-08-28 11:20:06",
  "updatedate": "2017-08-28 11:20:06"
 }, {
  "id": 50,
  "title": "拉夏贝尔2017夏季新款bf风韩版气质潮裙子学生衬衫式连衣裙衣女",
  "name": "bf风韩版气质潮裙子",
  "promotion": null,
  "size": "sml",
  "color": "粉红;白色;浅蓝",
  "picmini": "",
  "pic": "/upload/20170828112125_tb1j2cuxo4wmkjjsspmxxcznpxa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828112125_tb2k_foiyxlpufjsszfxxcsgxxa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_tb2nl6ht3jkpufjsszcxxxfsfxa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_tb2skz0dlu4h1jjszflxxafmpxa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_tb2wevji9hlpufjsspkxxa1apxa_!!2146742267.jpg_430x430q90.jpg",
  "parameter": "廓形:a型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:af5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:a字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:s、m、l、xl",
  "businessname": "北京房益宝",
  "typename": "连衣裙",
  "businessid": 1,
  "status": 1,
  "typeid": 8,
  "brandid": null,
  "price1": 199.00,
  "price2": 399.00,
  "longpic": "",
  "score": 19,
  "createdate": "2017-08-28 11:21:49",
  "updatedate": "2017-08-28 11:21:49"
 }
 ]
}

ps:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线json代码检验、检验、美化、格式化工具:

json在线格式化工具:

在线xml/json互相转换工具:

json代码在线格式化/美化/压缩/编辑/转换工具:

在线json压缩/转义工具:

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery操作json数据技巧汇总》、《jquery中ajax用法总结》、《jquery常用插件及用法总结》、《jquery扩展技巧总结》及《jquery选择器用法总结

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