Class: JSON

SuperMap.Format.JSON

安全的读写 JSON 的解析类。使用 SuperMap.Format.JSON 构造函数创建新实例。

new SuperMap.Format.JSON(options)

common/format/JSON.js, line 11
Name Type Description
options Object 可选

参数。

Name Type Default Description
indent string " " 可选

用于格式化输出,indent 字符串会在每次缩进的时候使用一次。

space string " " 可选

用于格式化输出,space 字符串会在名值对的 ":" 后边添加。

newline string "\n" 可选

用于格式化输出, newline 字符串会用在每一个名值对或数组项末尾。

level number 0 可选

用于格式化输出, 表示的是缩进级别。

pretty boolean false 可选

是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。

nativeJSON boolean 可选

需要被注册的监听器对象。

Extends

Members

dataObject

当 keepData 属性设置为 true,这是传递给 read 操作的要被解析的字符串。

indentstring

用于格式化输出,indent 字符串会在每次缩进的时候使用一次。

Default Value:
" "

keepDataObject

保持最近读到的数据的引用(通过 属性)。

levelnumber

用于格式化输出, 表示的是缩进级别。

nativeJSONboolean

判断浏览器是否原生支持 JSON 格式数据。

newlinestring

用于格式化输出, newline 字符串会用在每一个名值对或数组项末尾。

Default Value:
"\n"

prettyboolean

是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。

serialize

提供一些类型对象转 JSON 字符串的方法。

spacestring

用于格式化输出,space 字符串会在名值对的 ":" 后边添加。

Default Value:
" "

Methods

inherited destroy()

common/format/Format.js, line 38

销毁该格式类,释放相关资源。

read(json, filter){Object}

common/format/JSON.js, line 223

将一个符合 JSON 结构的字符串进行解析。

Name Type Description
json string

符合 JSON 结构的字符串。

filter function

过滤方法,最终结果的每一个键值对都会调用该过滤方法,并在对应的值的位置替换成该方法返回的值。

Returns:
Type Description
Object 对象,数组,字符串或数字。

write(value, pretty){string}

common/format/JSON.js, line 247

序列化一个对象到一个符合 JSON 格式的字符串。

Name Type Default Description
value object | string | Array | number | boolean

需要被序列化的对象,数组,字符串,数字,布尔值。

pretty boolean false 可选

是否在序列化的时候使用额外的空格控制结构。在 write 方法中使用。

Returns:
Type Description
string 符合 JSON 格式的字符串。