Package io.keikai.json
Class JSONValue
java.lang.Object
io.keikai.json.JSONValue
Utilities to encode and decode data in JSON format.
To decode, use
parse(String).
To encode, use toJSONString(java.lang.Object).- Author:
- FangYidong<fangyidong@yahoo.com.cn>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).static voidescape(String s, StringBuilder sb) static ObjectParse (a.k.a., decode) JSON text into java object from the input source.static ObjectParse (a.k.a., decode) JSON text into java object from the string.static StringtoJSONString(boolean value) Converts a boolean to JSON textstatic StringtoJSONString(byte value) Converts a byte to JSON textstatic StringtoJSONString(char value) Converts a char to JSON textstatic StringtoJSONString(double value) Converts a double to JSON textstatic StringtoJSONString(float value) Converts a float to JSON textstatic StringtoJSONString(int value) Converts an integer to JSON textstatic StringtoJSONString(long value) Converts a long to JSON textstatic StringtoJSONString(short value) Converts a short to JSON textstatic StringtoJSONString(Object value) Convert (a.k.a., encode) an object to JSON text.static StringtoJSONString(String key, Object value, StringBuilder sb)
-
Constructor Details
-
JSONValue
public JSONValue()
-
-
Method Details
-
parse
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
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
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
Converts an integer to JSON textpatched by tomyeh
-
toJSONString
Converts a long to JSON textpatched by tomyeh
-
toJSONString
Converts a short to JSON textpatched by tomyeh
-
toJSONString
Converts a double to JSON textpatched by tomyeh
-
toJSONString
Converts a float to JSON textpatched by tomyeh
-
toJSONString
Converts a byte to JSON textpatched by tomyeh
-
toJSONString
Converts a boolean to JSON textpatched by tomyeh
-
toJSONString
Converts a char to JSON textpatched by tomyeh
-
escape
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).- Parameters:
s-- Returns:
- the resulting string
-
toJSONString
-
escape
- Parameters:
s- - Must not be null.sb-
-