10.jmeter jsr223 javascript 深度比对json object
function sortJSON(data, key, way) {
//log.info(" " + key + " ------------------- " + typeof(key));
return data.sort(function(a, b) {
var x = a[key]; var y = b[key];
if (way === '' ) { return ((x < y) ? - : ((x > y) ? : )); }
if (way === '') { return ((x > y) ? - : ((x < y) ? : )); }
});
}
function isArray(what) {
return Object.prototype.toString.call(what) === '[object Array]';
}
var deepequals = function ( x, y ) {
if ( x === y ) return true;
// if both x and y are null or undefined and exactly the same
if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) return false;
// if they are not strictly equal, they both need to be Objects
if ( x.constructor !== y.constructor ) return false;
// they must have the exact same prototype chain, the closest we can do is
// test there constructor.
// log.info("1111111111111111111111 "+ typeof("payMethod") + "" + Object.keys(x)[0] + "" + typeof(Object.keys(x)[0]));
var sortkey2 = "payMethod";
if(isArray(x) && x.length > && typeof x[] == 'object' && Object.keys(x[])[] === "payMethod" ) {
//log.info(JSON.stringify(x)+" ======== "+ Object.keys(x));
//log.info(JSON.stringify(y)+" ======== "+ Object.keys(y));
sortkey2 = Object.keys(x[])[];
if(isArray(x)) { sortJSON(x,sortkey2, '');}
if(isArray(y)) { sortJSON(y,sortkey2, ''); }
//log.info(JSON.stringify(x)+" ======== "+ Object.keys(x));
//log.info(JSON.stringify(y)+" ======== "+ Object.keys(y));
}
//if(sortkey2 == sortkey) log.info("same string " + sortkey);
// if(isArray(x)) sortJSON(x,'a', '123');
// if(isArray(y)) sortJSON(y,'a', '123');
for ( var p in x ) {
// log.info(p+":"+ JSON.stringify(x[p]) + " ====== " + JSON.stringify(y[p]));
if ( ! x.hasOwnProperty( p ) ) continue;
// other properties were tested using x.constructor === y.constructor
if ( ! y.hasOwnProperty( p ) ) { log.info(JSON.stringify(x)+"\n================属性不一致 ===============\n"+JSON.stringify(y)); return false; }
// allows to compare x[ p ] and y[ p ] when set to undefined
if ( x[ p ] === y[ p ] ) continue;
// if they have the same strict value or identity then they are equal
if ( typeof( x[ p ] ) !== "object" ) { log.info(JSON.stringify(x)+"\n================值不一致===============\n"+JSON.stringify(y)); return false; };
// Numbers, Strings, Functions, Booleans must be strictly equal
if ( ! deepequals( x[ p ], y[ p ] ) ) return false;
// Objects and Arrays must be tested recursively
}
for ( p in y ) {
if ( y.hasOwnProperty( p ) && ! x.hasOwnProperty( p ) ) { log.info(JSON.stringify(x)+"\n================反向检查属性不一致===============\n"+JSON.stringify(y)); return false; };
// allows x[ p ] to be set to undefined
}
return true;
}
//Object.prototype.deepEquals = deepEquals;
var beforeObject = JSON.parse(vars.get("83response"));
var afterObject = JSON.parse(prev.getResponseDataAsString());
if(deepequals( beforeObject, afterObject )){
log.info("deep equals");
}
else{
// log.info(deepequals(testa,testb));
AssertionResult.setFailure(true);
AssertionResult.setFailureMessage("content not deep equal ");
AssertionResult.setResultForFailure("content not deep equal");
}
10.jmeter jsr223 javascript 深度比对json object的更多相关文章
- javascript深度克隆与javascript的继承实现
1.javascript深度克隆: //注意这里的对象包括object和array function cloneObject(obj){ var o = obj.constructor === Arr ...
- JavaScript(8)——JSON
JSON 啊呀呀,终于写到了JSON了.莫名的开心,虽然还是被说进度慢,不过,我不管,我就是开心.恩,好好学习,好好加油.(这是一段毫无逻辑的话,我也不知道说啥了) JSON是JavaScript的一 ...
- Javascript学习之:JSON
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于ECMAScript的一个子集,采用完全独立于语言的文本格式.这些特性使JSON成为理想的数据交换 ...
- JavaScript:基础扩展(1)——JSON
JavaScript:扩展知识(1)——JSON 理解: 关于 JSON,最重要的是要理解它是一种数据格式,不是一种编程语言.虽然具有相同的语法形式,但 JSON 并不从属于 JavaScript.而 ...
- 为新项目添彩的 10+ 超有用 JavaScript 库
快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中. <HTML开发Mac OS App 视频教程> 土豆网同步更新:http: ...
- [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")
javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢? 原因在于: ...
- JavaScript标准库之——JSON
JSON 对象包含了两个方法,一是解析 JavaScript Object Notation (JSON),二是将值转换为 JSON.这个对象本身不能被调用或者作为构造函数,除了它的这两个方法属性外 ...
- JavaScript Patterns 3.5 JSON
JSON: JavaScript Object Notation {"name": "value", "some": [1, 2, 3]} ...
- JavaScript的Eval与JSON.parse的区别
JavaScript的Eval与JSON.parse的区别 json的定义以及用法: JSON(JavaScript Object Notation)是一种轻量级的数据格式,采用完全独立于语言的文本格 ...
随机推荐
- 回溯---N皇后
N 皇后 51. N-Queens (Hard) 题目描述: 在n*n的矩阵中摆放n个皇后,并且每个皇后不能在同一列,同一个对角线上,求所有的n皇后解. 思路分析: 一行一行地摆放,在确定一行 ...
- Leetcode Lect7 哈希表
传统的哈希表 对于长度为n的哈希表,它的存储过程如下: 根据 key 计算出它的哈希值 h=hash(key) 假设箱子的个数为 n,那么这个键值对应该放在第 (h % n) 个箱子中 如果该箱子中已 ...
- React框架新闻网站学习过程中遇到的错误总结
1.安装指定版本插件命令 npm install 插件名字@1.1.4(版本号) --save 或 yarn add 插件名字@1.1.4(版本号) --dev 2.Error:‘Link’ is n ...
- Docker镜像恢复与迁移
首先我们先删除掉 mycentos_new:1.1 镜像(注意先停止并删除所有引用了的容器) docker rmi mycentos_new:1.1 然后执行此命令进行恢复 mycentos_new: ...
- log4j常用的配置文件
# priority :debug<info<warn<error #you cannot specify every priority with different file fo ...
- 网络拓扑_配置hybrid端口
目的:实现不同VLAN间的PC不可互访, 但不同VLAN的PC均可以访问服务器. 例: VLAN5与VLAN10的PC不可以互通,但它们均可与服务器VLAN50互通. 拓扑图:
- MongoDB的应用
一.MongoDB后台管理 # ./mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoD ...
- django之mysql数据库的配置和orm交互
一:django默认数据库的配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path. ...
- django之模型类在视图中的应用
一:模型类直接从把前端表单传入的值,进行存储. @csrf_exempt def regist(request): if request.method == 'POST': form = UserFo ...
- NASA CEA 安装指南
有用的网站: http://www.engr.colostate.edu/~marchese/combustion08/cec.html 1 把三个压缩包解压到同一个Ubuntu文件夹CEAexec下 ...