Class JSONUtils
java.lang.Object
org.springframework.extensions.webscripts.json.JSONUtils
Collection of JSON Utility methods.
This class is immutable.
- Author:
- Roy Wetherall, Kevin Roast
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionencodeJSONString(Object value) Encodes a JSON string valueorg.json.simple.JSONObjecttoJSONObject(Object object) Converts the given JavaScript native object to a org.json.simple.JSONObject Java Object.toJSONString(Object object) Converts a given JavaScript native object and converts it to the relevant JSON string.org.mozilla.javascript.ScriptableObjectTakes 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.
-
Constructor Details
-
JSONUtils
public JSONUtils()
-
-
Method Details
-
toJSONString
Converts a given JavaScript native object and converts it to the relevant JSON string.- Parameters:
object- JavaScript object- Returns:
- String JSON
- Throws:
IOException
-
toJSONObject
Converts 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:
IOException
-
toObject
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
Encodes a JSON string value- Parameters:
value- value to encode- Returns:
- String encoded value
-