Package org.pepstock.charba.client.utils
Class JSON
- java.lang.Object
-
- org.pepstock.charba.client.utils.JSON
-
@JsType(isNative=true, namespace="<global>") public final class JSON extends Object
This is the wrapper to JSON java script object.
The JSON object contains methods for parsing JSON and converting values to JSON.- Author:
- Andrea "Stock" Stocchero
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JSON.Replacer
A function that alters the behavior of the stringification process.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Array>
TparseForArray(String text)
Parses a JSON string, constructing the JavaScript array described by the string.static NativeObject
parseForObject(String text)
Parses a JSON string, constructing the JavaScript value or object described by the string.static String
stringify(Object obj)
Converts a JavaScript object or value to a JSON string.static String
stringify(Object obj, int spaces)
Converts a JavaScript object or value to a JSON string.static String
stringifyNativeObject(NativeObject obj, int spaces)
Converts a JavaScript object or value to a JSON string, using a specific replacer to avoid to print internal keys of CHART.jsstatic String
stringifyWithReplacer(Object obj)
Converts a JavaScript object or value to a JSON string, the space value is set to -1 that no space should be used and uses a default replacer to avoidTypeError: cyclic object value
.static String
stringifyWithReplacer(Object obj, int spaces)
Converts a JavaScript object or value to a JSON string, using a default replacer to avoidTypeError: cyclic object value
.static String
stringifyWithReplacer(Object obj, JSON.Replacer replacer, int spaces)
Converts a JavaScript object or value to a JSON string.
-
-
-
Method Detail
-
parseForObject
@JsOverlay public static NativeObject parseForObject(String text)
Parses a JSON string, constructing the JavaScript value or object described by the string.- Parameters:
text
- the string to parse as JSON.- Returns:
- the object corresponding to the given JSON text.
-
parseForArray
@JsOverlay public static <T extends Array> T parseForArray(String text)
Parses a JSON string, constructing the JavaScript array described by the string.- Type Parameters:
T
- type of native array- Parameters:
text
- the string to parse as JSON.- Returns:
- the array corresponding to the given JSON text.
-
stringify
@JsOverlay public static String stringify(Object obj)
Converts a JavaScript object or value to a JSON string. By default, the space value is set to -1 that no space should be used.- Parameters:
obj
- The value to convert to a JSON string.- Returns:
- A JSON string representing the given value.
-
stringify
@JsOverlay public static String stringify(Object obj, int spaces)
Converts a JavaScript object or value to a JSON string.- Parameters:
obj
- The value to convert to a JSON string.spaces
- it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.- Returns:
- A JSON string representing the given value.
-
stringifyWithReplacer
@JsOverlay public static String stringifyWithReplacer(Object obj)
Converts a JavaScript object or value to a JSON string, the space value is set to -1 that no space should be used and uses a default replacer to avoidTypeError: cyclic object value
.- Parameters:
obj
- The value to convert to a JSON string.- Returns:
- A JSON string representing the given value.
-
stringifyWithReplacer
@JsOverlay public static String stringifyWithReplacer(Object obj, int spaces)
Converts a JavaScript object or value to a JSON string, using a default replacer to avoidTypeError: cyclic object value
.- Parameters:
obj
- The value to convert to a JSON string.spaces
- it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.- Returns:
- A JSON string representing the given value.
-
stringifyWithReplacer
@JsOverlay public static String stringifyWithReplacer(Object obj, JSON.Replacer replacer, int spaces)
Converts a JavaScript object or value to a JSON string.- Parameters:
obj
- The value to convert to a JSON string.replacer
- A function that alters the behavior of the stringification process.spaces
- it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.- Returns:
- A JSON string representing the given value.
-
stringifyNativeObject
@JsOverlay public static String stringifyNativeObject(NativeObject obj, int spaces)
Converts a JavaScript object or value to a JSON string, using a specific replacer to avoid to print internal keys of CHART.js- Parameters:
obj
- The value to convert to a JSON string.spaces
- it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.- Returns:
- A JSON string representing the given value.
-
-