Package com.biglybt.util
Class JSONUtils
- java.lang.Object
-
- com.biglybt.util.JSONUtils
-
public class JSONUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description JSONUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.Object
coerce(java.lang.Object value)
static java.util.Map
decodeJSON(java.lang.String json)
decodes JSON formatted text into a map.static java.lang.String
encodeToJSON(java.util.Collection list)
static java.lang.String
encodeToJSON(java.util.Map map)
Encodes a map into a JSON formatted string.private static JSONArray
encodeToJSONArray(java.util.Collection list)
static JSONObject
encodeToJSONObject(java.util.Map map)
encodes a map into a JSONObject.static void
main(java.lang.String[] args)
-
-
-
Method Detail
-
decodeJSON
public static java.util.Map decodeJSON(java.lang.String json)
decodes JSON formatted text into a map.- Returns:
- Map parsed from a JSON formatted string
If the json text is not a map, a map with the key "value" will be returned. the value of "value" will either be an List, String, Number, Boolean, or null
if the String is formatted badly, null is returned
-
encodeToJSONObject
public static JSONObject encodeToJSONObject(java.util.Map map)
encodes a map into a JSONObject.It's recommended that you use
encodeToJSON(Map)
instead- Parameters:
map
-- Returns:
- Since:
- 3.0.1.5
-
encodeToJSON
public static java.lang.String encodeToJSON(java.util.Map map)
Encodes a map into a JSON formatted string.Handles multiple layers of Maps and Lists. Handls String, Number, Boolean, and null values.
- Parameters:
map
- Map to change into a JSON formatted string- Returns:
- JSON formatted string
- Since:
- 3.0.1.5
-
encodeToJSON
public static java.lang.String encodeToJSON(java.util.Collection list)
-
coerce
private static java.lang.Object coerce(java.lang.Object value)
-
encodeToJSONArray
private static JSONArray encodeToJSONArray(java.util.Collection list)
- Parameters:
value
-- Returns:
- Since:
- 3.0.1.5
-
main
public static void main(java.lang.String[] args)
-
-