加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FastJSON.js 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
冰儿! 提交于 2019-07-06 14:28 . create
const FastJSON = (function () {
let at;
this.format = function (str) {
let obj = JSON.parse(str);
at = obj;
obj = checkArgs(obj);
return obj;
};
let isObject = function (obj) {
return "object" == typeof obj
&& "[object object]" == Object.prototype.toString.call(obj)
.toLowerCase();
};
let checkArgs = function (obj) {
for (let para in obj) {
if (para == "_super_GXFastJSON") continue;
let pobj = obj[para];
pobj._super_GXFastJSON = obj;
if (isObject(pobj)) {
if (pobj.$ref) {
let g = pobj.$ref;
let p;
let b = false;
let first = g.substring(0, 1);
switch (first) {
case '@':
p = at;
break;
case '$':
let ss = g.split(".");
p = at;
for (let i = 1; i < ss.length; i++) {
p = p[ss[i]];
}
break;
case '.':
p = pobj;
for (let i = 0; i < g.length; i++) {
p = p._super_GXFastJSON;
}
break;
}
obj[para] = p;
} else {
let r = checkArgs(pobj);
}
}
delete pobj._super_GXFastJSON;
}
return obj;
}
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化