Package io.keikai.json
Class JSONValue
- java.lang.Object
-
- io.keikai.json.JSONValue
-
public class JSONValue extends Object
Utilities to encode and decode data in JSON format. To decode, useparse(String)
. To encode, usetoJSONString(java.lang.Object)
.- Author:
- FangYidong
-
-
Constructor Summary
Constructors Constructor Description JSONValue()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
escape(String s)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).static void
escape(String s, StringBuilder sb)
static Object
parse(Reader in)
Parse (a.k.a., decode) JSON text into java object from the input source.static Object
parse(String s)
Parse (a.k.a., decode) JSON text into java object from the string.static String
toJSONString(boolean value)
Converts a boolean to JSON textstatic String
toJSONString(byte value)
Converts a byte to JSON textstatic String
toJSONString(char value)
Converts a char to JSON textstatic String
toJSONString(double value)
Converts a double to JSON textstatic String
toJSONString(float value)
Converts a float to JSON textstatic String
toJSONString(int value)
Converts an integer to JSON textstatic String
toJSONString(long value)
Converts a long to JSON textstatic String
toJSONString(short value)
Converts a short to JSON textstatic String
toJSONString(Object value)
Convert (a.k.a., encode) an object to JSON text.static String
toJSONString(String key, Object value, StringBuilder sb)
-
-
-
Method Detail
-
parse
public static Object parse(Reader in) throws IOException
Parse (a.k.a., decode) JSON text into java object from the input source.- Parameters:
in
- the input to parse.- Returns:
- Instance of the following:
JSONObject
(also java.util.Map),JSONArray
(also java.util.List), java.lang.String, java.lang.Number, java.lang.Boolean, null. If in is null, null is returned. - Throws:
IOException
-
parse
public static Object parse(String s)
Parse (a.k.a., decode) JSON text into java object from the string.- Returns:
- the decoded object. If s is null, null is returned.
-
toJSONString
public static String toJSONString(Object value)
Convert (a.k.a., encode) an object to JSON text.If this object is a Map or a List, and it's also a JSONAware, JSONAware will be considered firstly.
DO NOT call this method from toJSONString() of a class that implements both JSONAware and Map or List with "this" as the parameter, use JSONObject.toJSONString(Map) or JSONArray.toJSONString(List) instead.
- Parameters:
value
-- Returns:
- JSON text, or "null" if value is null or it's an NaN or an INF number.
-
toJSONString
public static String toJSONString(int value)
Converts an integer to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(long value)
Converts a long to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(short value)
Converts a short to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(double value)
Converts a double to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(float value)
Converts a float to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(byte value)
Converts a byte to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(boolean value)
Converts a boolean to JSON textpatched by tomyeh
-
toJSONString
public static String toJSONString(char value)
Converts a char to JSON textpatched by tomyeh
-
escape
public static String escape(String s)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).- Parameters:
s
-- Returns:
- the resulting string
-
toJSONString
public static String toJSONString(String key, Object value, StringBuilder sb)
-
escape
public static void escape(String s, StringBuilder sb)
- Parameters:
s
- - Must not be null.sb
-
-
-