|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.hdcookbook.grin.util.JsonIO
public class JsonIO
This contains utility methods to read and write JSON-formatted objects. See http://json.org for the extremely simple syntax. In addition to that syntax, the reader discards whitespace, and comments in the "//", "/*" and "#" form.
JSON has a clear mapping to Java types that we use in this class:
JSON TYPE -> Java Type Object -> HashMap Array -> Object[] String -> String Number -> java.lang.Number (subclass determined by value) true/false -> Boolean null -> nullFor numbers, the reader will produce Integer, Long or Double; the writer will accept Integer, Long, Float or Double.
Method Summary | |
---|---|
static java.lang.Object |
readJSON(java.io.Reader rdr)
Read a JSON object from rdr. |
static void |
writeJSON(java.io.Writer out,
java.lang.Object value)
Write a JSON object to out. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void writeJSON(java.io.Writer out, java.lang.Object value) throws java.io.IOException
out
- The stream to write to. A buffered writer is
recommended; a UTF-8 character encoding is common
for JSON streams.
java.io.IOException
- if there is an underlying IO exception, or if value
contains an invalid type.JsonIO
public static java.lang.Object readJSON(java.io.Reader rdr) throws java.io.IOException
rdr
- The stream to read from. A buffered reader is
recommended; a UTF-8 character encoding is common
for JSON streams. The reader must be one where
markSupported() returns true, e.g. a BufferedReader.
java.io.IOException
- if there is an underlying IO exception, a
syntax error, or if rdr.markSupported is false.JsonIO
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |