197197 if (val[0] instanceof Object && (val[0] instanceof Array == false)) { // && JSONObject.isArrayKey(key, null, isRestful)) {
198198 // alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
199199
200- var ckey = key.substring(0, key.lastIndexOf('[]'));
200+ var ckey = key == null ? null : key .substring(0, key.lastIndexOf('[]'));
201201
202- var aliaIndex = ckey.indexOf(':');
202+ var aliaIndex = ckey == null ? -1 : ckey .indexOf(':');
203203 var objName = aliaIndex < 0 ? ckey : ckey.substring(0, aliaIndex);
204204
205- var firstIndex = objName.indexOf('-');
205+ var firstIndex = objName == null ? -1 : objName .indexOf('-');
206206 var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
207207
208208 for (var i = 0; i < val.length; i++) {
270270 }
271271 }
272272 else if (val instanceof Object) {
273- var aliaIndex = key.indexOf(':');
273+ var aliaIndex = key == null ? -1 : key .indexOf(':');
274274 var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
275275
276276 // var newVal = JSON.parse(JSON.stringify(val))
@@ -1519,16 +1519,118 @@ https://github.com/Tencent/APIJSON/issues
15191519 } catch (ex) {
15201520 log(ex)
15211521 }
1522+
1523+ var path = null;
1524+ var key = null;
1525+ var thiz = {
1526+ _$_path_$_: null,
1527+ _$_table_$_: null
1528+ };
1529+
15221530 if (isSingle || ret instanceof Array || (ret instanceof Object == false)) {
1523- this.jsonhtml = ret
1531+ var val = ret;
1532+ if (isSingle != true && val instanceof Array && val[0] instanceof Object && (val[0] instanceof Array == false)) {
1533+ // alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
1534+ var ckey = key == null ? null : key.substring(0, key.lastIndexOf('[]'));
1535+
1536+ var aliaIndex = ckey == null ? -1 : ckey.indexOf(':');
1537+ var objName = aliaIndex < 0 ? ckey : ckey.substring(0, aliaIndex);
1538+
1539+ var firstIndex = objName == null ? -1 : objName.indexOf('-');
1540+ var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
1541+
1542+ for (var i = 0; i < val.length; i++) {
1543+ var vi = val[i]
1544+
1545+ if (vi instanceof Object && vi instanceof Array == false && JSONObject.isTableKey(firstKey, val, isRestful)) {
1546+ // var newVal = JSON.parse(JSON.stringify(val[i]))
1547+ if (vi == null) {
1548+ continue
1549+ }
1550+
1551+ var curPath = '' + i;
1552+ var curTable = firstKey;
1553+ var thiz = {
1554+ _$_path_$_: curPath,
1555+ _$_table_$_: curTable
1556+ };
1557+
1558+ var newVal = {};
1559+ for (var k in vi) {
1560+ newVal[k] = vi[k]; //提升性能
1561+ if (this.isFullAssert) {
1562+ try {
1563+ var tr = this.currentRemoteItem.TestRecord || {};
1564+ var d = this.currentRemoteItem.Document || {};
1565+ var standard = this.isMLEnabled ? tr.standard : tr.response;
1566+ var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
1567+ var tests = this.tests[String(this.currentAccountIndex)] || {};
1568+ var responseObj = (tests[d.id] || {})[0]
1569+
1570+ var pathUri = (StringUtil.isEmpty(curPath, false) ? '' : curPath + '/') + k;
1571+ var pathKeys = StringUtil.split(pathUri, '/');
1572+ var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
1573+ var real = JSONResponse.getValByPath(responseObj, pathKeys);
1574+ var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
1575+ cmp.path = pathUri;
1576+ var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
1577+ thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
1578+ var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
1579+ thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1580+ } catch (e) {
1581+ thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
1582+ var countKey = '_$_redCount_$_';
1583+ thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1584+ }
1585+ }
1586+
1587+ delete vi[k]
1588+ }
1589+
1590+ vi._$_this_$_ = JSON.stringify(thiz)
1591+ for (var k in newVal) {
1592+ vi[k] = newVal[k]
1593+ }
1594+ }
1595+
1596+ }
1597+ }
1598+
1599+ this.jsonhtml = val;
15241600 }
15251601 else {
1526- this.jsonhtml = Object.assign({
1527- _$_this_$_: JSON.stringify({
1528- _$_path_$_: null,
1529- _$_table_$_: null
1530- })
1531- }, ret)
1602+ for (var k in ret) {
1603+ if (this.isFullAssert) {
1604+ try {
1605+ var tr = this.currentRemoteItem.TestRecord || {};
1606+ var d = this.currentRemoteItem.Document || {};
1607+ var standard = this.isMLEnabled ? tr.standard : tr.response;
1608+ var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
1609+ var tests = this.tests[String(this.currentAccountIndex)] || {};
1610+ var responseObj = (tests[d.id] || {})[0]
1611+
1612+ var pathUri = k;
1613+ var pathKeys = StringUtil.split(pathUri, '/');
1614+ var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
1615+ var real = JSONResponse.getValByPath(responseObj, pathKeys);
1616+ // c = JSONResponse.compareWithBefore(target, real, path);
1617+ var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
1618+ cmp.path = pathUri;
1619+ var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
1620+ thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
1621+ var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
1622+ thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1623+ } catch (e) {
1624+ thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
1625+ var countKey = '_$_redCount_$_';
1626+ thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1627+ }
1628+ }
1629+ }
1630+
1631+ this.jsonhtml = Object.assign({
1632+ _$_this_$_: JSON.stringify(thiz)
1633+ }, ret)
15321634 }
15331635
15341636 }
@@ -1844,7 +1946,7 @@ https://github.com/Tencent/APIJSON/issues
18441946 var name = item == null ? '' : StringUtil.get(item.name);
18451947 target.value = text = before + name + after
18461948 if (target == vScript) { // 不这样会自动回滚
1847- App .scripts[App .scriptType][App .scriptBelongId][App .isPreScript ? 'pre' : 'post'].script = text
1949+ this .scripts[this .scriptType][this .scriptBelongId][this .isPreScript ? 'pre' : 'post'].script = text
18481950 }
18491951 else if (target == vInput) {
18501952 inputted = target.value;
@@ -1870,7 +1972,7 @@ https://github.com/Tencent/APIJSON/issues
18701972 }
18711973
18721974 if (isInputValue != true) {
1873- App .showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
1975+ this .showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
18741976 }
18751977 } else {
18761978 target.selectionStart = selectionStart;
0 commit comments