分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

post请求获取json数据 解析json数据

发布时间:2023-09-06 01:43责任编辑:董明明关键词:jsjson
 ???<script> ???????window.onload = function () { ???????????var str; ??????????// console.log(@ViewBag.ID); ???????????$.post("/ServiceBills/ServiceBills/UpdateA", ???????????????{ id: @ViewBag.ID}, ???????????????function (data) { ???????????????????for (var attr in data) { ??????????????????????// console.log(attr);//name,age,gender ???????????????????????//console.log(data[attr]);//jack,25,male ?//值 ???????????????????????//console.log(typeof json1[attr]); ???????????????????????// $("#" + attr).val("111111111"); ???????????????????????$("#" + attr).val(data[attr]); ?//id ???????????????????????if ((data[attr] + "").indexOf("/Date(") != -1) { ?//时间 ???????????????????????????str = data[attr] + ""; ???????????????????????????str = timestampToTime(str.substring(6, str.length - 2)); //转换时间 ?????????????????????????// ?console.log(str); ???????????????????????} ???????????????????????else { ???????????????????????????str = data[attr]; ???????????????????????} ???????????????????????if ((attr + "").indexOf("workResult") != -1) { //包含workResult字符串 ???????????????????????????console.log("++++"); ???????????????????????????str = null; ?????????????????????????????????????????????????} ???????????????????????if ((attr + "").indexOf("UserSatisfaction") != -1) { ???????????????????????????console.log("----"); ???????????????????????????str = null; ???????????????????????} ???????????????????????if (str != null) { ???????????????????????????$("input[name=‘" + attr + "‘]").val(str); //输入框 ??????????????????????????} ??????????????????????????????????????????????//复选框 ???????????????????????if ((attr + "").indexOf("demandType") != -1) { ?//包含该字符串 ???????????????????????????var strs = (data[attr] + "").split(","); ?//输出这个字符串分割为数组 ???????????????????????????//获取集合 ???????????????????????????var objs = document.getElementsByName("demandType[]"); //获得对象集合 ??????????????????????????// console.log(objs); ???????????????????????????for (var i = 0; i < objs.length; i++) { ???????????????????????????????for (var j = 0; j < strs.length; j++) { ???????????????????????????????????if (strs[j].indexOf(objs[i].value) > -1) { //判断对象的值是否在这个数组中 ??????????????????????????????????????// console.log(strs[j]); ???????????????????????????????????????objs[i].checked = true; ??????//选中复选框 ???????????????????????????????????????????????????????????????????} ???????????????????????????????}; ???????????????????????????} ???????????????????????} ???????????????????????if ((attr + "").indexOf("userDemand") != -1) { ?//包含该字符串 ???????????????????????????var strs = (data[attr] + "").split(","); ?//输出这个字符串分割为数组 ???????????????????????????//获取集合 ???????????????????????????var objs = document.getElementsByName("userDemand[]"); //获得对象集合 ??????????????????????????// console.log(objs); ???????????????????????????for (var i = 0; i < objs.length; i++) { ???????????????????????????????for (var j = 0; j < strs.length; j++) { ???????????????????????????????????if (strs[j].indexOf(objs[i].value) > -1) { //判断对象的值是否在这个数组中 ???????????????????????????????????????//console.log(strs[j]); ???????????????????????????????????????objs[i].checked = true; ??????//选中复选框 ???????????????????????????????????????????????????????????????????} ???????????????????????????????}; ???????????????????????????} ???????????????????????} ???????????????????????//单选框 ??????????????????????// workResult ???????????????????????if ((attr + "").indexOf("workResult") != -1){ ???????????????????????????var str0 = data[attr] + ""; ???????????????????????????var objs = document.getElementsByName("workResult"); //获得对象集合 ??????????????????????????// console.log(objs); ???????????????????????????for (var i = 0; i < objs.length; i++) { ???????????????????????????????//console.log(objs.length); ??????????????????????????????????????????????????????if (str0.indexOf(objs[i].value) > -1){ ???????????????????????????????????objs[i].checked = true; ???????????????????????????????????console.log(objs[i].value); ???????????????????????????????} ?????????????????????????????????????????????????????????} ???????????????????????} ???????????????????????if ((attr + "").indexOf("UserSatisfaction") != -1) { ???????????????????????????var str0 = data[attr] + ""; ???????????????????????????var objs = document.getElementsByName("UserSatisfaction"); //获得对象集合 ???????????????????????????for (var i = 0; i < objs.length; i++) { ???????????????????????????????if (str0.indexOf(objs[i].value) > -1) { ???????????????????????????????????objs[i].checked = true; ???????????????????????????????????console.log(objs[i].value); ???????????????????????????????} ???????????????????????????} ???????????????????????} ???????????????????} ???????????????}); ???????} ???????function timestampToTime(timestamp) { ???????????var date = new Date(timestamp * 1);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 ???????????Y = date.getFullYear() + ‘-‘; ???????????M = (date.getMonth() + 1 < 10 ? ‘0‘ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘-‘; ???????????D = date.getDate() + ‘ ‘; ???????????h = date.getHours() + ‘:‘; ???????????m = date.getMinutes() + ‘:‘; ???????????s = date.getSeconds(); ???????????return Y + M + D + h + m + s; ???????} ???</script>

post请求获取json数据 解析json数据

原文地址:https://www.cnblogs.com/enych/p/8460740.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved