Code example for JSONTokener

Methods: back, next, nextValue

0
        String string = "{\"abc\":\"123\"}";
        buf = string.getBytes();
        ByteArrayInputStream is = new ByteArrayInputStream(buf);
        try 
        { 
            jsontokener = new JSONTokener(is);
            assertEquals('{', jsontokener.next());
            assertEquals("abc", jsontokener.nextValue());
            assertEquals(':', jsontokener.next());
            jsontokener.back();
            jsontokener.back();
        } catch (JSONException e)
        { 
            assertEquals("Stepping back two steps is not supported",e.getMessage());
        } 
    } 
     
    /** 
     * Tests the next method using fake input stream to test ioexception. 
     */ 
    public void testNext_FakeInputStreamToTestIoexception()