JSONParser jParser = new JSONParser(); String json = jParser.getJSONFromUrl(url);
JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(stringToParse);
public Object parse(Reader in) throws IOException, ParseException{ return parse(in, (ContainerFactory)null); }
public void parse(String s, ContentHandler contentHandler, boolean isResume) throws ParseException{ StringReader in=new StringReader(s); try{ parse(in, contentHandler, isResume); } catch(IOException ie){ /* * Actually it will never happen. */ throw new ParseException(-1, ParseException.ERROR_UNEXPECTED_EXCEPTION, ie); } }
JSONObject json = (JSONObject)new JSONParser().parse("{\"name\":\"MyNode\", \"width\":200, \"height\":100}"); System.out.println("name=" + json.get("name")); System.out.println("width=" + json.get("width"));
/** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; }
private static int [] zzUnpackAction() { int [] result = new int[45]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; }
private static int [] zzUnpackAttribute() { int [] result = new int[45]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; }
/** * @return The position of the beginning of the current token. */ public int getPosition(){ return lexer.getPosition(); }
private static int [] zzUnpackRowMap() { int [] result = new int[45]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; }
private List createArrayContainer(ContainerFactory containerFactory){ if(containerFactory == null) return new JSONArray(); List l = containerFactory.creatArrayContainer(); if(l == null) return new JSONArray(); return l; }
public static Object parseWithException(String s) throws ParseException{ JSONParser parser=new JSONParser(); return parser.parse(s); }
public void parse(String s, ContentHandler contentHandler) throws ParseException{ parse(s, contentHandler, false); }
public Object parse(String s, ContainerFactory containerFactory) throws ParseException{ StringReader in=new StringReader(s); try{ return parse(in, containerFactory); } catch(IOException ie){ /* * Actually it will never happen. */ throw new ParseException(-1, ParseException.ERROR_UNEXPECTED_EXCEPTION, ie); } }
private Object parse(String s) { try { JSONParser parser = new JSONParser(); return parser.parse(s); } catch (Exception e) { throw new IllegalStateException("Invalid JSON: " + s, e); } }
public void parse(Reader in, ContentHandler contentHandler) throws IOException, ParseException{ parse(in, contentHandler, false); }
public Object parse(String s) throws ParseException{ return parse(s, (ContainerFactory)null); }
private JSONObject getArtifactMetadata(String location, String host, Integer port) { String metadataStr = null; metadataStr = doGet("/api/storage", location, host, port); if (metadataStr == null) { return null; } JSONObject returnValue; try { returnValue = (JSONObject) jsonParser.parse(metadataStr); } catch (ParseException e) { LOG.error("Could not parse JSON string {}", metadataStr, e); return null; } return returnValue; }