public final class JsonUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static StringBuilder |
escape(String str)
Escapes characters in the specified string that must be escaped as defined
in RFC 4627, Section
2.5.
|
static boolean |
isStructural(int ch)
Tests whether
ch is a structural char, which is one of: |
static boolean |
isWhitespace(int ch)
Tests whether the specified
int is JSON whitespace char, which is
one of: |
static <T extends Number> |
parseNumber(Class<T> type,
String str)
Parses a number from the specified string by the rules defined in
RFC 4627, Section 2.4.
|
static String |
unescape(String str)
Unescapes string-literal unicode (
"
") and two-character
("\n") escape codes into UTF-8 as defined in
RFC 4627, Section 2.5. |
static String |
unescapeForString(String str)
Unescapes string-literal unicode (
"
") and two-character
("\n") escape codes, except for the double quote ("\"")
and reverse solidus ("\\"), into UTF-8 as defined in
RFC 4627, Section 2.5. |
public static boolean isStructural(int ch)
ch is a structural char, which is one of:
{ } [ ] : ,
ch - The char to test.true if ch is a structural char, otherwise
false.public static boolean isWhitespace(int ch)
int is JSON whitespace char, which is
one of:
' ','\n','\r', or'\t'
ch - The int to test.true if the specified int is an ANSI whitespace
char; otherwise false.public static <T extends Number> T parseNumber(Class<T> type, String str) throws JsonParseException
T - The type parameter for the return instance.type - The class of the return instance.str - The string to parse.type representing the parsed string.JsonParseException - If a parsing error has occurred.IllegalArgumentException - If the specified string is empty, or if an
instance of the specific class type does not define
<init>(String), valueOf(String), or
fromString(String).NullPointerException - If the specified string is null.public static StringBuilder escape(String str)
"\""), reverse solidus
("\\"), and the control characters (U+0000 through
U+001F).
This method escapes the following characters in string-literal two-character form:
{'\n', '\r', '\t', '\b', '\f'} -> {"\\n", "\\r", "\\t", "\\b", "\\f"}
str - The string to be escaped.unescape(String)public static String unescapeForString(String str)
"
") and two-character
("\n") escape codes, except for the double quote ("\"")
and reverse solidus ("\\"), into UTF-8 as defined in
RFC 4627, Section 2.5.
This method deliberately excludes the double quote ("\"") and
reverse solidus ("\\"), as these characters are necessary to be
able to differentiate the double quote from string boundaries, and thus the
reverse solidus from the escape character.
str - The string to be unescaped."\"") and reverse solidus
("\\") preserved.unescape(String)public static String unescape(String str)
"
") and two-character
("\n") escape codes into UTF-8 as defined in
RFC 4627, Section 2.5.str - The string to be unescaped.Copyright © 2020 OpenJAX. All rights reserved.