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的更多相关文章

  1. javascript深度克隆与javascript的继承实现

    1.javascript深度克隆: //注意这里的对象包括object和array function cloneObject(obj){ var o = obj.constructor === Arr ...

  2. JavaScript(8)——JSON

    JSON 啊呀呀,终于写到了JSON了.莫名的开心,虽然还是被说进度慢,不过,我不管,我就是开心.恩,好好学习,好好加油.(这是一段毫无逻辑的话,我也不知道说啥了) JSON是JavaScript的一 ...

  3. Javascript学习之:JSON

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于ECMAScript的一个子集,采用完全独立于语言的文本格式.这些特性使JSON成为理想的数据交换 ...

  4. JavaScript:基础扩展(1)——JSON

    JavaScript:扩展知识(1)——JSON 理解: 关于 JSON,最重要的是要理解它是一种数据格式,不是一种编程语言.虽然具有相同的语法形式,但 JSON 并不从属于 JavaScript.而 ...

  5. 为新项目添彩的 10+ 超有用 JavaScript 库

    快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中.   <HTML开发Mac OS App 视频教程> 土豆网同步更新:http: ...

  6. [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")

    javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢?   原因在于: ...

  7. JavaScript标准库之——JSON

    JSON 对象包含了两个方法,一是解析 JavaScript Object Notation (JSON),二是将值转换为 JSON.这个对象本身不能被调用或者作为构造函数,除了它的这两个方法属性外 ...

  8. JavaScript Patterns 3.5 JSON

    JSON: JavaScript Object Notation {"name": "value", "some": [1, 2, 3]}  ...

  9. JavaScript的Eval与JSON.parse的区别

    JavaScript的Eval与JSON.parse的区别 json的定义以及用法: JSON(JavaScript Object Notation)是一种轻量级的数据格式,采用完全独立于语言的文本格 ...

随机推荐

  1. Linux下CMake简明教程

    转载地址:https://blog.csdn.net/whahu1989/article/details/82078563 CMake是开源.跨平台的构建工具,可以让我们通过编写简单的配置文件去生成本 ...

  2. Form表单组件验证

    第一版:最基本版本 views源码 #——————————————————————form验证—————————————— from django import forms from django.f ...

  3. Linux查看当前目录下所有文件中包含map的行记录

    find yaochi_e.prm |xargs grep -ri "map" grep -n "map" *.prm|grep -v "\-\-ma ...

  4. java httpclient basic授权

    import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpS ...

  5. numpy中tile的用法

    a=arange(1,3) #a的结果是: array([1,2]) 1,当 tile(a,1) 时: tile(a,1) #结果是 array([1,2]) tile(a,2) #结果是 array ...

  6. postgresql windows 服务启动失败

    1命令行 启动服务 pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" start 2 查看状态 pg_ctl -D "C: ...

  7. 二、MyBatis-HelloWorld

    环境准备 1.创建数据库表 create table tbl_employee ( id ) primary key AUTO_INCREMENT comment "ID", la ...

  8. SSM三大框架整合梳理

    整合步骤 0.搭建动态web项目 1.需要的jar包 spring(包括springmvc) mybatis相关jar包 mybatis与spring的整合包(个人建议尽量使用高版本的,避免出现一些奇 ...

  9. spring boot构建

    1.新建Maven工程 1.File-->new-->project-->maven project 2.webapp 3.工程名称 k3 2.Maven 三个常用命令 选 项目右击 ...

  10. POJ 2449 Remmarguts' Date ( 第 k 短路 && A*算法 )

    题意 : 给出一个有向图.求起点 s 到终点 t 的第 k 短路.不存在则输出 -1 #include<stdio.h> #include<string.h> #include ...