let json = {/**判断JSON格式*/ isJSON: function (str) {if (typeof str == "string") {try {var obj = JSON.parse(str);if (typeof obj == "object" && obj) {return true;} else {return false;}} catch (e) {return false;}} else if (typeof str == "object") {return Object.prototype.toString.call(obj).toLocaleLowerCase() == "[object object]" && !obj.length;}return false;},
/**合并string类型的json*/ mergeJsonString: function () {return JSON.parse((jsonStr1 + jsonStr2).replace(/}{/g, ","));}, /**拼接两个json*/ mergeJsonObject: function (json1, json2) {for (var i in json1) {json2[i] = json1[i];}return json2;},
/**将JSON对象转换为字符串*//** param 将要转为URL参数字符串的对象,key URL参数字符串的前缀, encode true/false 是否进行URL编码 默认为true return URL参数字符串,index不需要传参*/ toGetString: function (param, key, encode, index, firstStr='?') {index || (index = 0);index++;if (param == null) return;var ps = "";var t = typeof (param);if (t == "string" || t == "number" || t == "boolean") {ps += "&" + key + "=" + ((encode == null || encode) ? encodeURIComponent(param) : param);} else {for (var i in param) {var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);ps += json.toGetString(param[i], k, encode, index, firstStr);}}index == 1 && (ps = ps.replace("&", firstStr));return ps;/*测试用例*//* var obj = {a: '1', 'b': {c: '3'}, d: [{e: '4'}]}; alert(json.toGetString(obj)); alert(json.toGetString(obj, 'CLASS'));*/},
/**JSON转GET请求参数(只针对包含一个层级的json格式)*/ toGetStringForOneDepthLevel: function (json, firstStr='?') {return firstStr+JSON.stringify(json).replace(/ |
|
|"|{|}/g, "").replace(/,/g, "&").replace(/:/g, "=");},
/**GET请求参数转JSON(只针对包含一个层级的json格式)*/ fromGetStringForOneDepthLevel: function (getString) {return JSON.parse("{"" + getString.substr(1 + getString.indexOf("?")).replace(/&/g, "","").replace(/=/g, "":"") + ""}");},
/**格式化json字符串格式*/string: function (json) {return JSON.stringify(json, null, 4);},
/**获取json对象一级属性个数*/ length: function (obj) {var count = 0;for (var i in obj) {count++;}return count;},//比较两个json是否相同isObj(object) {return object && typeof (object) == "object" && Object.prototype.toString.call(object).toLowerCase() == "[object object]";},isArray(object) {return object && typeof (object) == "object" && object.constructor == Array;},getLength(object) {var count = 0;for (var i in object) count++;return count;},compare(objA, objB) {if (!this.isObj(objA) || !this.isObj(objB)) return false; //判断类型是否正确if (this.getLength(objA) != this.getLength(objB)) return false; //判断长度是否一致return this.compareObj(objA, objB, true);//默认为true},compareObj(objA, objB, flag) {for (var key in objA) {if (!flag) //跳出整个循环break;if (!objB.hasOwnProperty(key)) {flag = false;break;}if (!this.isArray(objA[key])) { //子级不是数组时,比较属性值if (objB[key] != objA[key]) {flag = false;break;}} else {if (!this.isArray(objB[key])) {flag = false;break;}var oA = objA[key], oB = objB[key];if (oA.length != oB.length) {flag = false;break;}for (var k in oA) {if (!flag) //这里跳出循环是为了不让递归继续break;flag = this.compareObj(oA[k], oB[k], flag);}}}return flag;}
};
//去掉值为null或undefined的对象属性
Object.keys(d).forEach(k=>d[k]==null&&delete d[k]);//去掉值为null或undefined或''的对象属性
Object.keys(d).forEach(k=>(d[k]==null||d[k]==='')&&delete d[k]);
/*判断屏幕宽高比是否为16:9*/ function isScreen16to9() {return window.screen.height / window.screen.width === 9 / 16; }...
/*关闭、刷新、跳转、离开当前网页前提示*/ onbeforeunload = function () {return false; }; ...
项目结构 index.js //必须要安装否则就别想运行了❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤ //npm i body-parser -D & cnpm i express & cnpm i node-xlsx & cnp...
一、递归 函数 为什么要有函数,提高代码的可读性,避免重复的代码,提高代码的复用性 在函数中能用return的不要print 1、递归的最大深度997 def foo(n):print(n)n+=1foo(n) foo(1) 递归的最大深度 2、修改递归的最大深度 由此我们可以看出,未报错之前能看到的最大数...
2019独角兽企业重金招聘Python工程师标准>>> a different object with the same identifier value was already associated with the session 一个经典的hibernate错误:a different object with the...
//获取某一个cookie的值 const getCookie = key => {var k = key, dc = document.cookie;if (dc.length > 0) {var s = dc.indexOf(k + "=");if (s != -1) {s = s + k.length + 1;var e = d...
var SGheadMapPoints = {/*obj={ maxLng: minLng: maxLat: minLat: maxCount:最大人数 minCount:最小人数 total:点位数量 }*/get: function (obj) {var arr = [];obj.maxCount || (obj.maxCount...
创建index.html代码如下
//自动搜索指定的请柬 var alertTipText = "请柬找到了,就在这个网页里面,自己仔细看吧"; var delay = 1 * 1000;//1秒后循环下一页寻找 /*获取子DOM元素在父元素里面的索引位置(是第几个元素)*/ function getNodeListIndex(childNode) {return c...
获取天气情况(不支持跨域) /*json原生获取*/ function getJSON() {var XML;var url = "http://wthrcdn.etouch.cn/weather_mini?city=杭州";if (window.XMLHttpRequest) {XML = new XMLHttpRequest(...