Class JSONUtils
- java.lang.Object
-
- org.springframework.extensions.webscripts.json.JSONUtils
-
public class JSONUtils extends java.lang.ObjectCollection of JSON Utility methods. This class is immutable.- Author:
- Roy Wetherall, Kevin Roast
-
-
Constructor Summary
Constructors Constructor Description JSONUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectencodeJSONString(java.lang.Object value)Encodes a JSON string valueorg.json.simple.JSONObjecttoJSONObject(java.lang.Object object)Converts the given JavaScript native object to a org.json.simple.JSONObject Java Object.java.lang.StringtoJSONString(java.lang.Object object)Converts a given JavaScript native object and converts it to the relevant JSON string.org.mozilla.javascript.ScriptableObjecttoObject(java.lang.String jsonString)Takes a JSON string and converts it to a native java script object or arrayorg.mozilla.javascript.NativeArraytoObject(org.json.simple.JSONArray jsonArray)Takes a JSON array and converts it to a native JS array.org.mozilla.javascript.NativeObjecttoObject(org.json.simple.JSONObject jsonObject)Takes a JSON object and converts it to a native JS object.
-
-
-
Method Detail
-
toJSONString
public java.lang.String toJSONString(java.lang.Object object) throws java.io.IOExceptionConverts a given JavaScript native object and converts it to the relevant JSON string.- Parameters:
object- JavaScript object- Returns:
- String JSON
- Throws:
java.io.IOException
-
toJSONObject
public org.json.simple.JSONObject toJSONObject(java.lang.Object object) throws java.io.IOExceptionConverts the given JavaScript native object to a org.json.simple.JSONObject Java Object. This is a specialized method only used by routines that will later expect a JSONObject.- Parameters:
object- JavaScript native object- Returns:
- JSONObject
- Throws:
java.io.IOException
-
toObject
public org.mozilla.javascript.ScriptableObject toObject(java.lang.String jsonString)
Takes a JSON string and converts it to a native java script object or array- Parameters:
jsonString- a valid json string- Returns:
- NativeObject the created native JS object that represents the JSON object or array
-
toObject
public org.mozilla.javascript.NativeObject toObject(org.json.simple.JSONObject jsonObject)
Takes a JSON object and converts it to a native JS object.- Parameters:
jsonObject- the json object- Returns:
- NativeObject the created native object
-
toObject
public org.mozilla.javascript.NativeArray toObject(org.json.simple.JSONArray jsonArray)
Takes a JSON array and converts it to a native JS array.- Parameters:
jsonArray- the json array- Returns:
- NativeObject the created native array
-
encodeJSONString
public java.lang.Object encodeJSONString(java.lang.Object value)
Encodes a JSON string value- Parameters:
value- value to encode- Returns:
- String encoded value
-
-