public class JSONParser extends Object
// Open a JSON file in the classpath.
final JSONParser lParser = new JSONParser(JSONTest.class.getResourceAsStream("/example.json"));
// Parse the first object in the file.
final JSONValue lMyObject = lParser.nextValue();
After the parsing you have an object from the JSON model from package com.sdicons.json.model
.
You can map it to Java using the JSONMapper
or unmarshal it to Java using the JSONSerializer
.
Note that the rendering to text can be done using the render()
method.Constructor and Description |
---|
JSONParser(InputStream aStream)
Construct a parser using a stream.
|
JSONParser(InputStream aStream,
String aStreamName)
Construct a parser using a stream.
|
JSONParser(Reader aReader)
Construct a parser using a reader.
|
JSONParser(Reader aReader,
String aStreamName)
Construct a parser using a reader.
|
JSONParser(String jsonText) |
Modifier and Type | Method and Description |
---|---|
JSONValue |
nextValue()
Read the next JSON structure from the stream and convert it into a
Java model.
|
protected JSONValue |
parseJson(StringBuilder parsed) |
public JSONParser(InputStream aStream, String aStreamName) throws ParserException
aStream
- A stream containing JSON text.aStreamName
- A String that describes the stream, it will be attached to
all JSON objects in the model which are generated from this parser. This makes it
possible to identify the stream where the object came from.ParserException
- When an error occurs during parser construction.public JSONParser(InputStream aStream) throws ParserException
aStream
- A stream containing JSON text.ParserException
- When an error occurs during parser construction.public JSONParser(Reader aReader, String aStreamName) throws ParserException
aReader
- A reader containing JSON text.aStreamName
- A String that describes the stream, it will be attached to
all JSON objects in the model which are generated from this parser. This makes it
possible to identify the stream where the object came from.ParserException
- When an error occurs during parser construction.public JSONParser(Reader aReader) throws ParserException
aReader
- A reader containing JSON text.ParserException
- When an error occurs during parser construction.public JSONParser(String jsonText) throws ParserException
ParserException
public JSONValue nextValue() throws ParserException
ParserException
- When a lexer/parser error occured while parsing the stream.protected JSONValue parseJson(StringBuilder parsed)
Copyright © 2012. All Rights Reserved.