to.etc.webapp.ajax.renderer
Class JSONParser

java.lang.Object
  extended by to.etc.lexer.TextReaderBase
      extended by to.etc.lexer.ReaderScannerBase
          extended by to.etc.lexer.ReaderTokenizerBase
              extended by to.etc.webapp.ajax.renderer.JSONParser

public class JSONParser
extends ReaderTokenizerBase

This class parses JSON streams and creates a generic Java structure consisting of arrays and map's representing the JSON data.

Author:
Frits Jalvingh Created on Oct 19, 2006

Field Summary
 
Fields inherited from class to.etc.lexer.ReaderScannerBase
T_BASE_LAST, T_COMMENT, T_EOF, T_IDENT, T_IPADDR, T_NUMBER, T_STRING
 
Constructor Summary
JSONParser(java.io.Reader r)
           
 
Method Summary
static void main(java.lang.String[] args)
           
 java.lang.Object parse()
           
 java.lang.Object parseItem()
          Parse the JSON input and return a JSON data structure.
static java.lang.Object parseJSON(java.io.Reader in)
          Parse the input stream as a JSON structure.
static java.lang.Object parseJSON(java.io.Reader r, java.lang.Class<?> totype)
          Parse the input stream as a JSON object, and try to assign it's content to the specified class.
static java.lang.Object parseJSON(java.lang.String in)
          Parse the string as a JSON structure.
static java.lang.Object parseJSON(java.lang.String in, java.lang.Class<?> totype)
          Parse the input, and try to assign the JSON input to a created instance of the specified class.
protected  int scanString()
          Override to scan Javascript string constants.
 
Methods inherited from class to.etc.lexer.ReaderTokenizerBase
getLastToken, isKeepQuotes, nextToken, scanToken, setKeepQuotes, setReturnComment, setReturnNewline, setReturnWhitespace
 
Methods inherited from class to.etc.lexer.ReaderScannerBase
error, getSourceLocation, getTokenColumn, getTokenLine, isAllowNewlineInString, isIdChar, isIdStart, scanIdentifier, scanNumber, scanSimpleString, setAllowNewlineInString, skipWs, skipWsNoNL, startToken
 
Methods inherited from class to.etc.lexer.TextReaderBase
accept, accept, append, append, clearCopy, copy, copy, getCopied, getCurrentColumn, getCurrentLine, getSource, LA, LA, sb
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONParser

public JSONParser(java.io.Reader r)
Method Detail

parse

public java.lang.Object parse()
                       throws java.lang.Exception
Throws:
java.lang.Exception

scanString

protected int scanString()
                  throws java.io.IOException
Override to scan Javascript string constants.

Overrides:
scanString in class ReaderTokenizerBase
Throws:
java.io.IOException
See Also:
ReaderTokenizerBase.scanString()

parseItem

public java.lang.Object parseItem()
                           throws java.lang.Exception
Parse the JSON input and return a JSON data structure.

Returns:
Throws:
java.lang.Exception

parseJSON

public static java.lang.Object parseJSON(java.lang.String in,
                                         java.lang.Class<?> totype)
                                  throws java.lang.Exception
Parse the input, and try to assign the JSON input to a created instance of the specified class.

Throws:
java.lang.Exception

parseJSON

public static java.lang.Object parseJSON(java.io.Reader r,
                                         java.lang.Class<?> totype)
                                  throws java.lang.Exception
Parse the input stream as a JSON object, and try to assign it's content to the specified class.

Parameters:
r -
totype -
Returns:
Throws:
java.lang.Exception

parseJSON

public static java.lang.Object parseJSON(java.lang.String in)
                                  throws java.lang.Exception
Parse the string as a JSON structure. This returns a generic Java structure representing the JSON request, where all arrays are returned as List<Object>, all Javascript objects as a Map<Object, Object> and all primitives are translated to a reasonable Java type.

Throws:
java.lang.Exception

parseJSON

public static java.lang.Object parseJSON(java.io.Reader in)
                                  throws java.lang.Exception
Parse the input stream as a JSON structure. This returns a generic Java structure representing the JSON request, where all arrays are returned as List<Object>, all Javascript objects as a Map<Object, Object> and all primitives are translated to a reasonable Java type.

Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)