Package blackberry.common.util.json4j

Examples of blackberry.common.util.json4j.JSONException


    public Parser(Reader reader) throws JSONException {
        super();    
        try {
            this.tokenizer = new Tokenizer(reader, false);
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.setCause(iox);
            throw jex;
        }
    }
View Full Code Here


    public Parser(Reader reader, boolean strict) throws JSONException {
        super();    
        try {
            this.tokenizer = new Tokenizer(reader, strict);
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.setCause(iox);
            throw jex;
        }
    }
View Full Code Here

     */
    public JSONObject parse(boolean ordered) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.setCause(iox);
            throw jex;
        }
        return parseObject(ordered, null);
    }
View Full Code Here

     */
    public JSONObject parse(boolean ordered, JSONObject jObj) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.setCause(iox);
            throw jex;
        }
        return parseObject(ordered, jObj);
    }
View Full Code Here

     */
    public JSONArray parse(boolean ordered, JSONArray jObj) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.setCause(iox);
            throw jex;
        }
        return parseArray(ordered, jObj);
    }
View Full Code Here

                  //MSN NO ORDERED
                    result = new JSONObject();
                }
            }

            if (lastToken != Token.TokenBraceL) throw new JSONException("Expecting '{' " + tokenizer.onLineCol() + " instead, obtained token: '" + lastToken + "'");
            lastToken = tokenizer.next();

            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated object " + tokenizer.onLineCol());

                if (lastToken == Token.TokenBraceR) {
                    lastToken = tokenizer.next();
                    break;
                }

                if (!lastToken.isString()) throw new JSONException("Expecting string key " + tokenizer.onLineCol());
                String key = lastToken.getString();

                lastToken = tokenizer.next();
                if (lastToken != Token.TokenColon) throw new JSONException("Expecting colon " + tokenizer.onLineCol());

                lastToken = tokenizer.next();
                Object val = parseValue(ordered);

                result.put(key, val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                }

                else if (lastToken != Token.TokenBraceR) {
                    throw new JSONException("expecting either ',' or '}' " + tokenizer.onLineCol());
                }
            }
            return result;
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during object input read.");
            jex.setCause(iox);
            throw jex;
        }
    }
View Full Code Here

        } else {
            result = new JSONArray();
        }

        try {
            if (lastToken != Token.TokenBrackL) throw new JSONException("Expecting '[' " + tokenizer.onLineCol());
            lastToken = tokenizer.next();
            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated array " + tokenizer.onLineCol());

                /**
                 * End of the array.
                 */
                if (lastToken == Token.TokenBrackR) {
                    lastToken = tokenizer.next();
                    break;
                }

                Object val = parseValue(ordered);
                result.add(val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                } else if (lastToken != Token.TokenBrackR) {
                    throw new JSONException("expecting either ',' or ']' " + tokenizer.onLineCol());
                }
            }
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during array input read.");
            jex.setCause(iox);
            throw jex;
        }
        return result;
    }
View Full Code Here

     * @param ordered Flag to denote if the parse should contruct JSON objects and arrays which maintain serialization order of the attributes.    
     *
     * @throws JSONException Thrown if an IO error (read incomplete token) occurs.
     */
    public Object parseValue(boolean ordered) throws JSONException {
        if (lastToken == Token.TokenEOF) throw new JSONException("Expecting property value " + tokenizer.onLineCol());

        try {
            if (lastToken.isNumber()) {
                Object result = lastToken.getNumber();
                lastToken = tokenizer.next();
                return result;
            }

            if (lastToken.isString()) {
                Object result = lastToken.getString();
                lastToken = tokenizer.next();
                return result;
            }

            if (lastToken == Token.TokenFalse) {
                lastToken = tokenizer.next();
                return Boolean.FALSE;
            }

            if (lastToken == Token.TokenTrue) {
                lastToken = tokenizer.next();
                return Boolean.TRUE;
            }

            if (lastToken == Token.TokenNull) {
                lastToken = tokenizer.next();
                return JSONObject.NULL;
            }

            if (lastToken == Token.TokenBrackL) return parseArray(ordered, null);
            if (lastToken == Token.TokenBraceL) return parseObject(ordered, null);

        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during value input read.");
            jex.setCause(iox);
            throw jex;
        }
        throw new JSONException("Invalid token " + tokenizer.onLineCol());
    }
View Full Code Here

TOP

Related Classes of blackberry.common.util.json4j.JSONException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.