org.springframework.extensions.webscripts.json
Class JSONUtils

java.lang.Object
  extended by org.springframework.extensions.webscripts.json.JSONUtils

public class JSONUtils
extends Object

Collection of JSON Utility methods. This class is immutable.

Author:
Roy Wetherall

Constructor Summary
JSONUtils()
           
 
Method Summary
 Object encodeJSONString(Object value)
          Encodes a JSON string value
 String toJSONString(Object object)
          Converts a given JavaScript native object and converts it to the relevant JSON string.
 org.mozilla.javascript.NativeObject toObject(org.json.JSONObject jsonObject)
          Takes a JSON object and converts it to a native JS object.
 org.mozilla.javascript.NativeObject toObject(String jsonString)
          Takes a JSON string and converts it to a native java script object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONUtils

public JSONUtils()
Method Detail

toJSONString

public String toJSONString(Object object)
                    throws org.json.JSONException
Converts a given JavaScript native object and converts it to the relevant JSON string.

Parameters:
object - JavaScript object
Returns:
String JSON
Throws:
org.json.JSONException

toObject

public org.mozilla.javascript.NativeObject toObject(String jsonString)
                                             throws org.json.JSONException
Takes a JSON string and converts it to a native java script object

Parameters:
jsonString - a valid json string
Returns:
NativeObject the created native JS object that represents the JSON object
Throws:
org.json.JSONException

toObject

public org.mozilla.javascript.NativeObject toObject(org.json.JSONObject jsonObject)
                                             throws org.json.JSONException
Takes a JSON object and converts it to a native JS object.

Parameters:
jsonObject - the json object
Returns:
NativeObject the created native object
Throws:
org.json.JSONException

encodeJSONString

public Object encodeJSONString(Object value)
Encodes a JSON string value

Parameters:
value - value to encode
Returns:
String encoded value


Copyright © 2009 SpringSource, Inc. All Rights Reserved.