/** * Parse an unknown type. * * @return Object the next item * @throws JSONParseException if invalid JSON is found */ public Object parse() { return parse(null); }
/** * Parses an object for the form <i>{}</i> and <i>{ members }</i>. * * @return DBObject the next object * @throws JSONParseException if invalid JSON is found */ protected Object parseObject(final String name) { if (name != null) { _callback.objectStart(name); } else { _callback.objectStart(); } read('{'); char current = get(); while (get() != '}') { String key = parseString(false); read(':'); Object value = parse(key); doCallback(key, value); if ((current = get()) == ',') { read(','); } else { break; } } read('}'); return _callback.objectDone(); }
/** * Parses an object for the form <i>{}</i> and <i>{ members }</i>. * * @return DBObject the next object * @throws JSONParseException if invalid JSON is found */ protected Object parseObject(final String name) { if (name != null) { _callback.objectStart(name); } else { _callback.objectStart(); } read('{'); char current = get(); while (get() != '}') { String key = parseString(false); read(':'); Object value = parse(key); doCallback(key, value); if ((current = get()) == ',') { read(','); } else { break; } } read('}'); return _callback.objectDone(); }
/** * Parses a JSON string and constructs a corresponding Java object by calling the methods of a {@link org.bson.BSONCallback * BSONCallback} during parsing. If the callback {@code c} is null, this method is equivalent to {@link JSON#parse(String) * parse(String)}. * * @param s the string to parse * @param c the BSONCallback to call during parsing * @return a Java object representing the JSON data * @throws JSONParseException if s is not valid JSON */ public static Object parse(final String s, final BSONCallback c) { if (s == null || (s.trim()).equals("")) { return null; } JSONParser p = new JSONParser(s, c); return p.parse(); }
/** * Parses the next array. * * @return the array * @throws JSONParseException if invalid JSON is found */ protected Object parseArray(final String name) { if (name != null) { _callback.arrayStart(name); } else { _callback.arrayStart(); } read('['); int i = 0; char current = get(); while (current != ']') { String elemName = String.valueOf(i++); Object elem = parse(elemName); doCallback(elemName, elem); if ((current = get()) == ',') { read(','); } else if (current == ']') { break; } else { throw new JSONParseException(s, pos); } } read(']'); return _callback.arrayDone(); }
/** * Parse an unknown type. * * @return Object the next item * @throws JSONParseException if invalid JSON is found */ public Object parse() { return parse(null); }
/** * Parses a JSON string and constructs a corresponding Java object by calling the methods of a {@link org.bson.BSONCallback * BSONCallback} during parsing. If the callback {@code c} is null, this method is equivalent to {@link JSON#parse(String) * parse(String)}. * * @param s the string to parse * @param c the BSONCallback to call during parsing * @return a Java object representing the JSON data * @throws JSONParseException if s is not valid JSON */ public static Object parse(final String s, final BSONCallback c) { if (s == null || (s.trim()).equals("")) { return null; } JSONParser p = new JSONParser(s, c); return p.parse(); }
/** * Parses the next array. * * @return the array * @throws JSONParseException if invalid JSON is found */ protected Object parseArray(final String name) { if (name != null) { _callback.arrayStart(name); } else { _callback.arrayStart(); } read('['); int i = 0; char current = get(); while (current != ']') { String elemName = String.valueOf(i++); Object elem = parse(elemName); doCallback(elemName, elem); if ((current = get()) == ',') { read(','); } else if (current == ']') { break; } else { throw new JSONParseException(s, pos); } } read(']'); return _callback.arrayDone(); }