Class: JSON

SuperMap.Format.JSON

Parse class for safely reading and writing JSON. Create a new instance using SuperMap.Format.JSON constructor.

new SuperMap.Format.JSON(options)

JSON.js, line 4
Name Type Description
options Object optional

parameter.

Name Type Default Description
indent string " " optional

Used to format the output, the indent string is used once for each indentation.

space string " " optional

Used to format the output, the space string is added after the ":" of the name-value pair.

newline string "\n" optional

Used to format the output, the newline string is used at each end of the name value pair or array item.

level number 0 optional

Used to format the output, indicating the indentation level.

pretty boolean false optional

Whether to use extra space to control the structure when serializing. Used in the write method.

nativeJSON boolean optional

A listener object that needs to be registered.

Extends

Members

dataObject

When the keepData attribute is set to true, This is the string that is passed to the read operation to be parsed.

indentstring

Format output. For every indent, the indent string will use one time.

Default Value:
" "

keepDataObject

Keep a reference to the data that is read recently (through the attribute). The default value is false

levelinteger

use formatted output, the indentation level is expressed.

nativeJSONboolean

Determine whether browsers are native to support JSON format data.

newlinestring

Format output. newline string will be used for each name value pair or the last number of array.

Default Value:
'\n'

prettyboolean

Whether to use words wrap and indent to control the output.

serialize

A method of providing a number of type objects to a JSON string.

spacestring

Format output. space string wil be added after the name value pair ":".

Default Value:
" "

Methods

inherited destroy()

Format.js, line 36

Disposes the resource. The property that references resource is set to null.

read(json, filter){Object}

JSON.js, line 216

Parsing a string conforming to the JSON structure.

Name Type Description
json string

A string that conforms to the JSON structure.

filter function

The filtering method, each of the key value pairs of the final result will call the filter method and replace the value returned by the location of the corresponding value.

Returns:
Type Description
Object Object, array, string, or number.

write(value, pretty){string}

JSON.js, line 240

Serialize an object to a string that conforms to the JSON format.

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

object, array, string, number, boolean that needs to be serialized.

pretty boolean optional

Whether to use words wrap and indent to control the output.

Returns:
Type Description
string String conforming to JSON format