- public static Object parse(String s){
- StringReader in=new StringReader(s);
- return parse(in);
- }
-
- /**
- * Parse JSON text into java object from the input source.
- *
- * @see org.json.simple.parser.JSONParser
- *
- * @param in
- * @return Instance of the following:
- * org.json.simple.JSONObject,
- * org.json.simple.JSONArray,
- * java.lang.String,
- * java.lang.Number,
- * java.lang.Boolean,
- * null
- *
- * @throws IOException
- * @throws ParseException
- */
- public static Object parseWithException(Reader in) throws IOException, ParseException{
- JSONParser parser=new JSONParser();
- return parser.parse(in);
- }
-
- public static Object parseWithException(String s) throws ParseException{
- JSONParser parser=new JSONParser();
- return parser.parse(s);
- }
-
- /**
- * Encode an object into JSON text and write it to out.
- * <p>
- * 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.
- * <p>
- * 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.
- *
- * @see org.json.simple.JSONObject#writeJSONString(Map, Writer)
- * @see org.json.simple.JSONArray#writeJSONString(List, Writer)
- *
- * @param value
- * @param writer
- */
- public static void writeJSONString(Object value, Writer out) throws IOException {
- if(value == null){
- out.write("null");
- return;
- }
-
- if(value instanceof String){
- out.write('\"');
- out.write(escape((String)value));
- out.write('\"');
- return;
- }
-
- if(value instanceof Double){
- if(((Double)value).isInfinite() || ((Double)value).isNaN())
- out.write("null");
- else
- out.write(value.toString());
- return;
- }
-
- if(value instanceof Float){
- if(((Float)value).isInfinite() || ((Float)value).isNaN())
- out.write("null");
- else
- out.write(value.toString());
- return;
- }
-
- if(value instanceof Number){
- out.write(value.toString());
- return;
- }
-
- if(value instanceof Boolean){
- out.write(value.toString());
- return;
- }
-
- if((value instanceof JSONStreamAware)){
- ((JSONStreamAware)value).writeJSONString(out);
- return;
- }
-
- if((value instanceof JSONAware)){
- out.write(((JSONAware)value).toJSONString());
- return;
- }
-
- if(value instanceof Map){
- JSONObject.writeJSONString((Map)value, out);
- return;
- }
-
- if(value instanceof Collection){
- JSONArray.writeJSONString((Collection)value, out);
- return;
- }
-
- if(value instanceof byte[]){
- JSONArray.writeJSONString((byte[])value, out);
- return;
- }
-
- if(value instanceof short[]){
- JSONArray.writeJSONString((short[])value, out);
- return;
- }
-
- if(value instanceof int[]){
- JSONArray.writeJSONString((int[])value, out);
- return;
- }
-
- if(value instanceof long[]){
- JSONArray.writeJSONString((long[])value, out);
- return;
- }
-
- if(value instanceof float[]){
- JSONArray.writeJSONString((float[])value, out);
- return;
- }
-
- if(value instanceof double[]){
- JSONArray.writeJSONString((double[])value, out);
- return;
- }
-
- if(value instanceof boolean[]){
- JSONArray.writeJSONString((boolean[])value, out);
- return;
- }
-
- if(value instanceof char[]){
- JSONArray.writeJSONString((char[])value, out);
- return;
- }
-
- if(value instanceof Object[]){
- JSONArray.writeJSONString((Object[])value, out);
- return;
- }
-
- out.write(value.toString());
- }
+ public static Object parse(String s)
+ {
+ StringReader in = new StringReader(s);
+ return parse(in);
+ }
+
+ /**
+ * Parse JSON text into java object from the input source.
+ *
+ * @see org.json.simple.parser.JSONParser
+ *
+ * @param in
+ * @return Instance of the following: org.json.simple.JSONObject,
+ * org.json.simple.JSONArray, java.lang.String, java.lang.Number,
+ * java.lang.Boolean, null
+ *
+ * @throws IOException
+ * @throws ParseException
+ */
+ public static Object parseWithException(Reader in)
+ throws IOException, ParseException
+ {
+ JSONParser parser = new JSONParser();
+ return parser.parse(in);
+ }
+
+ public static Object parseWithException(String s) throws ParseException
+ {
+ JSONParser parser = new JSONParser();
+ return parser.parse(s);
+ }
+
+ /**
+ * Encode an object into JSON text and write it to out.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ *
+ * @see org.json.simple.JSONObject#writeJSONString(Map, Writer)
+ * @see org.json.simple.JSONArray#writeJSONString(List, Writer)
+ *
+ * @param value
+ * @param writer
+ */
+ public static void writeJSONString(Object value, Writer out)
+ throws IOException
+ {
+ if (value == null)
+ {
+ out.write("null");
+ return;
+ }
+
+ if (value instanceof String)
+ {
+ out.write('\"');
+ out.write(escape((String) value));
+ out.write('\"');
+ return;
+ }