public static ValidatingJsonMap fromJSON(Reader s, String includeLocation) { try { ValidatingJsonMap map = (ValidatingJsonMap) getObjectBuilder(new JSONParser(s)).getObject(); handleIncludes(map, includeLocation, 4); return map; } catch (IOException e) { throw new RuntimeException(); } }
public static Object fromJSONString(String json) { try { return new ObjectBuilder(new JSONParser(new StringReader( json))).getObject(); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Parse error", e); } }
@Override public NamedList<Object> processResponse(InputStream body, String encoding) { Map map = null; try { ObjectBuilder builder = new ObjectBuilder( new JSONParser(new InputStreamReader(body, encoding == null? "UTF-8": encoding))); map = (Map)builder.getObject(); } catch (IOException | JSONParser.ParseException e) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "parsing error", e); } NamedList<Object> list = new NamedList<Object>(); list.addAll(map); return list; }
public Object getVal() throws IOException { int ev = parser.lastEvent(); switch(ev) { case JSONParser.STRING: return getString(); case JSONParser.LONG: return getLong(); case JSONParser.NUMBER: return getNumber(); case JSONParser.BIGNUMBER: return getBigNumber(); case JSONParser.BOOLEAN: return getBoolean(); case JSONParser.NULL: return getNull(); case JSONParser.OBJECT_START: return getObject(); case JSONParser.OBJECT_END: return null; // OR ERROR? case JSONParser.ARRAY_START: return getArray(); case JSONParser.ARRAY_END: return null; // OR ERROR? case JSONParser.EOF: return null; // OR ERROR? default: return null; // OR ERROR? } }
public Object getVal() throws IOException { int ev = parser.lastEvent(); switch(ev) { case JSONParser.STRING: return getString(); case JSONParser.LONG: return getLong(); case JSONParser.NUMBER: return getNumber(); case JSONParser.BIGNUMBER: return getBigNumber(); case JSONParser.BOOLEAN: return getBoolean(); case JSONParser.NULL: return getNull(); case JSONParser.OBJECT_START: return getObject(); case JSONParser.OBJECT_END: return null; // OR ERROR? case JSONParser.ARRAY_START: return getArray(); case JSONParser.ARRAY_END: return null; // OR ERROR? case JSONParser.EOF: return null; // OR ERROR? default: return null; // OR ERROR? } }