开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
48 Star 115 Fork 4

SuperMap/iClient-JavaScript

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (81)
标签 (32)
master
v11.3.x
v12.1.0
v12.0.1
dependabot/npm_and_yarn/src/common/fast-xml-parser-5.7.0
snyk-fix-54d9e7714a681c45b3ad4dacb6c8592a
dependabot/npm_and_yarn/turf/turf-7.3.3
snyk-fix-abdb4bdebc8b86ad9f7bfae6309e58ad
snyk-fix-4712f7a861c430e813f85333e4bfed82
snyk-upgrade-e88282fa32778b721e99887d92f3a0a7
snyk-upgrade-9a49cfee0586b226f385660495928af1
snyk-upgrade-976578446f1da59fc1ae66384683a906
snyk-upgrade-9b8759143442723b128989c089b4f3c3
dependabot/npm_and_yarn/mapbox-gl-3.18.1
dependabot/npm_and_yarn/elastic/elasticsearch-9.2.1
dependabot/npm_and_yarn/nightwatch-3.15.0
dependabot/npm_and_yarn/chromedriver-145.0.0
snyk-fix-34e860bf6537d6ef593f3733a0a21b4c
v12.0.0
v11.1.1
12.1.0-r
12.0.1-r
12.0.0-r
11.3.0
11.1.2
11.2.1
11.2.0
11.1.1
11.1.0
11.1.0-beta
11.0.1
11.0.0
11.0.0-beta
10.2.1
10.2.0
10.1.3
10.1.2
10.1.1
10.1.0
10.1.0-beta
master
分支 (81)
标签 (32)
master
v11.3.x
v12.1.0
v12.0.1
dependabot/npm_and_yarn/src/common/fast-xml-parser-5.7.0
snyk-fix-54d9e7714a681c45b3ad4dacb6c8592a
dependabot/npm_and_yarn/turf/turf-7.3.3
snyk-fix-abdb4bdebc8b86ad9f7bfae6309e58ad
snyk-fix-4712f7a861c430e813f85333e4bfed82
snyk-upgrade-e88282fa32778b721e99887d92f3a0a7
snyk-upgrade-9a49cfee0586b226f385660495928af1
snyk-upgrade-976578446f1da59fc1ae66384683a906
snyk-upgrade-9b8759143442723b128989c089b4f3c3
dependabot/npm_and_yarn/mapbox-gl-3.18.1
dependabot/npm_and_yarn/elastic/elasticsearch-9.2.1
dependabot/npm_and_yarn/nightwatch-3.15.0
dependabot/npm_and_yarn/chromedriver-145.0.0
snyk-fix-34e860bf6537d6ef593f3733a0a21b4c
v12.0.0
v11.1.1
12.1.0-r
12.0.1-r
12.0.0-r
11.3.0
11.1.2
11.2.1
11.2.0
11.1.1
11.1.0
11.1.0-beta
11.0.1
11.0.0
11.0.0-beta
10.2.1
10.2.0
10.1.3
10.1.2
10.1.1
10.1.0
10.1.0-beta
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (81)
标签 (32)
master
v11.3.x
v12.1.0
v12.0.1
dependabot/npm_and_yarn/src/common/fast-xml-parser-5.7.0
snyk-fix-54d9e7714a681c45b3ad4dacb6c8592a
dependabot/npm_and_yarn/turf/turf-7.3.3
snyk-fix-abdb4bdebc8b86ad9f7bfae6309e58ad
snyk-fix-4712f7a861c430e813f85333e4bfed82
snyk-upgrade-e88282fa32778b721e99887d92f3a0a7
snyk-upgrade-9a49cfee0586b226f385660495928af1
snyk-upgrade-976578446f1da59fc1ae66384683a906
snyk-upgrade-9b8759143442723b128989c089b4f3c3
dependabot/npm_and_yarn/mapbox-gl-3.18.1
dependabot/npm_and_yarn/elastic/elasticsearch-9.2.1
dependabot/npm_and_yarn/nightwatch-3.15.0
dependabot/npm_and_yarn/chromedriver-145.0.0
snyk-fix-34e860bf6537d6ef593f3733a0a21b4c
v12.0.0
v11.1.1
12.1.0-r
12.0.1-r
12.0.0-r
11.3.0
11.1.2
11.2.1
11.2.0
11.1.1
11.1.0
11.1.0-beta
11.0.1
11.0.0
11.0.0-beta
10.2.1
10.2.0
10.1.3
10.1.2
10.1.1
10.1.0
10.1.0-beta
JSON.js 11.79 KB
一键复制 编辑 原始数据 按行查看 历史
songyumeng 提交于 2026年06月16日 14:56 +08:00 . 【copyright】2026
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/* Copyright© 2000 - 2026 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {
Format
} from './Format';
/**
* @class JSONFormat
* @aliasclass Format.JSON
* @deprecatedclass SuperMap.Format.JSON
* @classdesc 安全的读写 JSON 的解析类。使用 {@link JSONFormat} 构造函数创建新实例。
* @category BaseTypes Format
* @param {Object} [options] - 可选参数。
* @param {string} [options.indent=" "] - 用于格式化输出,indent 字符串会在每次缩进的时候使用一次。
* @param {string} [options.space=" "] - 用于格式化输出,space 字符串会在名值对的 ":" 后边添加。
* @param {string} [options.newline="\n"] - 用于格式化输出,newline 字符串会用在每一个名值对或数组项末尾。
* @param {number} [options.level=0] - 用于格式化输出,表示的是缩进级别。
* @param {boolean} [options.pretty=false] - 是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。
* @param {boolean} [options.nativeJSON] - 需要被注册的监听器对象。
* @extends {Format}
* @usage
*/
export class JSONFormat extends Format {
constructor(options) {
super(options);
/**
* @member {string} [JSONFormat.prototype.indent=" "]
* @description 用于格式化输出,indent 字符串会在每次缩进的时候使用一次。
*/
this.indent = "";
/**
* @member {string} [JSONFormat.prototype.space=" "]
* @description 用于格式化输出,space 字符串会在名值对的 ":" 后边添加。
*/
this.space = "";
/**
* @member {string} [JSONFormat.prototype.newline="\n"]
* @description 用于格式化输出,newline 字符串会用在每一个名值对或数组项末尾。
*/
this.newline = "\n";
/**
* @member {number} [JSONFormat.prototype.level=0]
* @description 用于格式化输出,表示的是缩进级别。
*/
this.level = 0;
/**
* @member {boolean} [JSONFormat.prototype.pretty=false]
* @description 是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。
*/
this.pretty = false;
/**
* @member {boolean} JSONFormat.prototype.nativeJSON
* @description 判断浏览器是否原生支持 JSON 格式数据。
*/
this.nativeJSON = (function () {
return !!(window.JSON && typeof JSON.parse === "function" && typeof JSON.stringify === "function");
})();
this.CLASS_NAME = "SuperMap.Format.JSON";
/**
* @member JSONFormat.prototype.serialize
* @description 提供一些类型对象转 JSON 字符串的方法。
*/
this.serialize = {
/**
* @function JSONFormat.serialize.object
* @description 把对象转换为 JSON 字符串。
* @param {Object} object - 可序列化的对象。
* @returns {string} JSON 字符串。
*/
'object': function (object) {
// three special objects that we want to treat differently
if (object == null) {
return "null";
}
if (object.constructor === Date) {
return this.serialize.date.apply(this, [object]);
}
if (object.constructor === Array) {
return this.serialize.array.apply(this, [object]);
}
var pieces = ['{'];
this.level += 1;
var key, keyJSON, valueJSON;
var addComma = false;
for (key in object) {
if (object.hasOwnProperty(key)) {
// recursive calls need to allow for sub-classing
keyJSON = this.write.apply(this,
[key, this.pretty]);
valueJSON = this.write.apply(this,
[object[key], this.pretty]);
if (keyJSON != null && valueJSON != null) {
if (addComma) {
pieces.push(',');
}
pieces.push(this.writeNewline(), this.writeIndent(),
keyJSON, ':', this.writeSpace(), valueJSON);
addComma = true;
}
}
}
this.level -= 1;
pieces.push(this.writeNewline(), this.writeIndent(), '}');
return pieces.join('');
},
/**
* @function JSONFormat.serialize.array
* @description 把数组转换成 JSON 字符串。
* @param {Array} array - 可序列化的数组。
* @returns {string} JSON 字符串。
*/
'array': function (array) {
var json;
var pieces = ['['];
this.level += 1;
for (var i = 0, len = array.length; i < len; ++i) {
// recursive calls need to allow for sub-classing
json = this.write.apply(this,
[array[i], this.pretty]);
if (json != null) {
if (i > 0) {
pieces.push(',');
}
pieces.push(this.writeNewline(), this.writeIndent(), json);
}
}
this.level -= 1;
pieces.push(this.writeNewline(), this.writeIndent(), ']');
return pieces.join('');
},
/**
* @function JSONFormat.serialize.string
* @description 把字符串转换成 JSON 字符串。
* @param {string} string - 可序列化的字符串。
* @returns {string} JSON 字符串。
*/
'string': function (string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can simply slap some quotes around it.
// Otherwise we must also replace the offending characters with safe
// sequences.
var m = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
/*eslint-disable no-control-regex*/
if (/["\\\x00-\x1f]/.test(string)) {
return '"' + string.replace(/([\x00-\x1f\\"])/g, function (a, b) {
var c = m[b];
if (c) {
return c;
}
c = b.charCodeAt();
return '\\u00' +
Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
}) + '"';
}
return '"' + string + '"';
},
/**
* @function JSONFormat.serialize.number
* @description 把数字转换成 JSON 字符串。
* @param {number} number - 可序列化的数字。
* @returns {string} JSON 字符串。
*/
'number': function (number) {
return isFinite(number) ? String(number) : "null";
},
/**
* @function JSONFormat.serialize.boolean
* @description Transform a boolean into a JSON string.
* @param {boolean} bool - The boolean to be serialized.
* @returns {string} A JSON string representing the boolean.
*/
'boolean': function (bool) {
return String(bool);
},
/**
* @function JSONFormat.serialize.object
* @description 将日期对象转换成 JSON 字符串。
* @param {Date} date - 可序列化的日期对象。
* @returns {string} JSON 字符串。
*/
'date': function (date) {
function format(number) {
// Format integers to have at least two digits.
return (number < 10) ? '0' + number : number;
}
return '"' + date.getFullYear() + '-' +
format(date.getMonth() + 1) + '-' +
format(date.getDate()) + 'T' +
format(date.getHours()) + ':' +
format(date.getMinutes()) + ':' +
format(date.getSeconds()) + '"';
}
};
}
/**
* @function JSONFormat.prototype.read
* @description 将一个符合 JSON 结构的字符串进行解析。
* @param {string} json - 符合 JSON 结构的字符串。
* @param {function} filter - 过滤方法,最终结果的每一个键值对都会调用该过滤方法,并在对应的值的位置替换成该方法返回的值。
* @returns {(Object|string|Array|number|boolean)} 对象,数组,字符串或数字。
*/
read(json, filter) {
var object;
if (this.nativeJSON) {
try {
object = JSON.parse(json, filter);
} catch (e) {
// Fall through if the regexp test fails.
return { data: json}
}
}
if (this.keepData) {
this.data = object;
}
return object;
}
/**
* @function JSONFormat.prototype.write
* @description 序列化一个对象到一个符合 JSON 格式的字符串。
* @param {Object|string|Array|number|boolean} value - 需要被序列化的对象,数组,字符串,数字,布尔值。
* @param {boolean} [pretty=false] - 是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。
* @returns {string} 符合 JSON 格式的字符串。
*
*/
write(value, pretty) {
this.pretty = !!pretty;
var json = null;
var type = typeof value;
if (this.serialize[type]) {
try {
json = (!this.pretty && this.nativeJSON) ?
JSON.stringify(value) :
this.serialize[type].apply(this, [value]);
} catch (err) {
//console.error("Trouble serializing: " + err);
}
}
return json;
}
/**
* @function JSONFormat.prototype.writeIndent
* @description 根据缩进级别输出一个缩进字符串。
* @private
* @returns {string} 一个适当的缩进字符串。
*/
writeIndent() {
var pieces = [];
if (this.pretty) {
for (var i = 0; i < this.level; ++i) {
pieces.push(this.indent);
}
}
return pieces.join('');
}
/**
* @function JSONFormat.prototype.writeNewline
* @description 在格式化输出模式情况下输出代表新一行的字符串。
* @private
* @returns {string} 代表新的一行的字符串。
*/
writeNewline() {
return (this.pretty) ? this.newline : '';
}
/**
* @function JSONFormat.prototype.writeSpace
* @private
* @description 在格式化输出模式情况下输出一个代表空格的字符串。
* @returns {string} 空格字符串。
*/
writeSpace() {
return (this.pretty) ? this.space : '';
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Modern GIS Web Client
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/isupermap/iClient-JavaScript.git
git@gitee.com:isupermap/iClient-JavaScript.git
isupermap
iClient-JavaScript
iClient-JavaScript
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /