@Test public void testInvalid() { String[] cases = { "", " ", "a", "false\"", "trues", "null1", "*", "00", "01", "08", "+0", "+2", "+2.3", "2.3.4", "2e2e2", "2e++0", "2e+-0", "2e--0", "2f", "0x10", "0 0", "0,0", "0 "\"", "\"\\", "\"\\\"", "\"\"\"", "\"\\a\"", "\"\\x00\"", "\"\\u+000\"", "\"\\u-000\"", "\"\u0000\"", "\"\n\"", "\"a\tb\"", "\"ab\rcd\"", "[", "]", "{", "}", "[}", "[,]", "[0,]", "[5 4]", "[5, 4,]", "[\"a\" \"b\"]", "[\"cc\" 3]", "[[]", "][", "[\"]", "{abc:0}", "{null:true}", "{\"a\":1,}", "{\"a\":1 \"b\":2}", "{}{}", "{{}}", }; for (String cs : cases) { try { Json.parse(cs); fail(); } catch (IllegalArgumentException e) {} } }
public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); static String serialize(Object obj); static Object parse(String str); static Object parseFromFile(File file); static Object parseFromFile(File file, Charset cs); static Object parseFromUrl(URL url); static Object parseFromUrl(URL url, Charset cs); static void serializeToFile(Object obj, File file); static void serializeToFile(Object obj, File file, Charset cs); @SuppressWarnings("unchecked") static Object getObject(Object root, Object... path); static boolean getBoolean(Object root, Object... path); static int getInt(Object root, Object... path); static long getLong(Object root, Object... path); static float getFloat(Object root, Object... path); static double getDouble(Object root, Object... path); static String getString(Object root, Object... path); @SuppressWarnings("unchecked") static List<Object> getList(Object root, Object... path); @SuppressWarnings("unchecked") static Map<String,Object> getMap(Object root, Object... path); }
Json { public static Object parse(String str) { StringStream ss = new StringStream(str); Object result = parseGeneral(ss); if (result instanceof Symbol) throw new IllegalArgumentException("Malformed JSON"); if (!isSymbol(parseGeneral(ss), -1)) throw new IllegalArgumentException("Malformed JSON"); return result; } private  Json(); static String serialize(Object obj); static Object parse(String str); static Object parseFromFile(File file); static Object parseFromFile(File file, Charset cs); static Object parseFromUrl(URL url); static Object parseFromUrl(URL url, Charset cs); static void serializeToFile(Object obj, File file); static void serializeToFile(Object obj, File file, Charset cs); @SuppressWarnings("unchecked") static Object getObject(Object root, Object... path); static boolean getBoolean(Object root, Object... path); static int getInt(Object root, Object... path); static long getLong(Object root, Object... path); static float getFloat(Object root, Object... path); static double getDouble(Object root, Object... path); static String getString(Object root, Object... path); @SuppressWarnings("unchecked") static List<Object> getList(Object root, Object... path); @SuppressWarnings("unchecked") static Map<String,Object> getMap(Object root, Object... path);  }