net.tomp2p.examples.json.simple
Class JSONValue

java.lang.Object
  extended by net.tomp2p.examples.json.simple.JSONValue

public class JSONValue
extends Object

Author:
FangYidong

Constructor Summary
JSONValue()
           
 
Method Summary
static String escape(String s)
          Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
static Object parse(Reader in)
          Parse JSON text into java object from the input source.
static Object parse(String s)
           
static Object parseWithException(Reader in)
          Parse JSON text into java object from the input source.
static Object parseWithException(String s)
           
static String toJSONString(Object value)
          Convert an object to JSON text.
static void writeJSONString(Object value, Writer out)
          Encode an object into JSON text and write it to out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONValue

public JSONValue()
Method Detail

parse

public static Object parse(Reader in)
Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception.

Parameters:
in -
Returns:
Instance of the following: org.json.simple.JSONObject, org.json.simple.JSONArray, java.lang.String, java.lang.Number, java.lang.Boolean, null
See Also:
org.json.simple.parser.JSONParser#parse(Reader), parseWithException(Reader)

parse

public static Object parse(String s)

parseWithException

public static Object parseWithException(Reader in)
                                 throws IOException,
                                        ParseException
Parse JSON text into java object from the input source.

Parameters:
in -
Returns:
Instance of the following: org.json.simple.JSONObject, org.json.simple.JSONArray, java.lang.String, java.lang.Number, java.lang.Boolean, null
Throws:
IOException
ParseException
See Also:
org.json.simple.parser.JSONParser

parseWithException

public static Object parseWithException(String s)
                                 throws ParseException
Throws:
ParseException

writeJSONString

public static void writeJSONString(Object value,
                                   Writer out)
                            throws IOException
Encode an object into JSON text and write it to out.

If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.

DO NOT call this method from writeJSONString(Writer) of a class that implements both JSONStreamAware and (Map or List) with "this" as the first parameter, use JSONObject.writeJSONString(Map, Writer) or JSONArray.writeJSONString(List, Writer) instead.

Parameters:
value -
writer -
Throws:
IOException
See Also:
org.json.simple.JSONObject#writeJSONString(Map, Writer), org.json.simple.JSONArray#writeJSONString(List, Writer)

toJSONString

public static String toJSONString(Object value)
Convert 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.
See Also:
org.json.simple.JSONObject#toJSONString(Map), org.json.simple.JSONArray#toJSONString(List)

escape

public static String escape(String s)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).

Parameters:
s -
Returns:


Copyright © 2012. All Rights Reserved.