Refine search
public JsonFile(File file) throws IOException{ super(); if(file == null) throw new IOException("File must not be null"); this.file = file; if(file.exists()){ JSONTokener tokener; tokener = new JSONTokener(new FileReader(file)); putAll(new JSONObject(tokener)); } else{ file.createNewFile(); commit(); } }
tokener = new JSONTokener(getCoordURL.openStream()); } catch (Exception e1) { e1.printStackTrace(); JSONObject obj = new JSONObject(tokener); wikiTokener = new JSONTokener(getWikiURL.openStream()); } catch (Exception e1) { e1.printStackTrace(); JSONObject wikiGeoResult = new JSONObject(wikiTokener);
public String toJson() { JSONObject jsonObject= new JSONObject(); try { jsonObject.put(CALLBACK_ID_STR, getCallbackId()); jsonObject.put(DATA_STR, getData()); jsonObject.put(HANDLER_NAME_STR, getHandlerName()); String data = getResponseData(); if (TextUtils.isEmpty(data)) { jsonObject.put(RESPONSE_DATA_STR, data); } else { jsonObject.put(RESPONSE_DATA_STR, new JSONTokener(data).nextValue()); } jsonObject.put(RESPONSE_DATA_STR, getResponseData()); jsonObject.put(RESPONSE_ID_STR, getResponseId()); return jsonObject.toString(); } catch (JSONException e) { e.printStackTrace(); } return null; }
private Object parse(String json) throws JSONException { JSONTokener tokener = new JSONTokener(json); char c = tokener.nextClean(); //peak ahead tokener.back(); //revert if (c == '{') { //json object JSONObject o = new JSONObject(tokener); return toMap(o); } else if (c == '[') { JSONArray a = new JSONArray(tokener); return toList(a); } else { //raw json value Object value = tokener.nextValue(); return convertIfNecessary(value); } }
final JSONTokener js = new JSONTokener(in); final JSONObject jsonObj = new JSONObject(js); final JSONObject application = jsonObj.getJSONObject("application"); final JSONArray instances = application.getJSONArray("instance");
public static Object getStringPropertyAsJSON( JSONObject jsonObject, String key, String nonJSONPropertyKey ) throws JSONException { Object value = jsonObject.opt(key); if (value != null && value instanceof String) { JSONTokener tokener = new JSONTokener((String) value); value = tokener.nextValue(); } if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) { if (nonJSONPropertyKey != null) { // Facebook sometimes gives us back a non-JSON value such as // literal "true" or "false" as a result. // If we got something like that, we present it to the caller as a JSONObject // with a single property. We only do this if the caller wants that behavior. jsonObject = new JSONObject(); jsonObject.putOpt(nonJSONPropertyKey, value); return jsonObject; } else { throw new FacebookException("Got an unexpected non-JSON object."); } } return value; }
@Override public boolean matches(Object item) { if(!String.class.isInstance(item)){ return false; } if(this.expected == null && "null".equals(item)){ return true; } JSONObject actual = null; try { actual = new JSONObject(new JSONTokener(item.toString())); } catch (JSONException e) { return false; } if(this.expected.length() != actual.length()) { return false; } JSONArray names = actual.names(); for(int i = 0, len = names.length(); i < len; i++){ try { String name = names.getString(i); if(!Objects.equals(expected.get(name), actual.get(name))){ return false; } } catch (JSONException e) { return false; } } return true; }
@Override public Object readFromReader(Reader reader) throws JSONException { return new JSONObject(new JSONTokener(reader)); }
public static String loadFromEtherpad(String etherpadUrlstub, String etherpadApikey, String padID) throws IOException { String padurl = etherpadUrlstub + "/api/1/getText?apikey=" + etherpadApikey + "&padID=" + padID; InputStream is = new URL(padurl).openStream(); JSONTokener serviceResponse = new JSONTokener(is); JSONObject json = new JSONObject(serviceResponse); String text = json.getJSONObject("data").getString("text"); return text; } }
public static JSONObject loadJSONObject(String source_url) throws IOException { byte[] b = load(source_url); return new JSONObject(new JSONTokener(new String(b, StandardCharsets.UTF_8))); } public static JSONObject loadJSONObject(String source_url, Map<String, byte[]> params) throws IOException {
public static JSONObject loadJSONObject(String source_url, Map<String, byte[]> params) throws IOException { byte[] b = load(source_url, params); return new JSONObject(new JSONTokener(new String(b, StandardCharsets.UTF_8))); }
public JSONObject read(String serviceName, String tableName, final String id) throws IOException { String s = this.db.read(serviceName, tableName, id); JSONTokener t = new JSONTokener(s); return new JSONObject(t); }
public JSONList(InputStream sourceStream) throws IOException { this(); BufferedReader br = new BufferedReader(new InputStreamReader(sourceStream, StandardCharsets.UTF_8)); String line; try { while ((line = br.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; JSONObject json = new JSONObject(new JSONTokener(line)); this.add(json); } } catch (JSONException e) { throw new IOException(e); } }
public JSONObject getJSONBody() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteStreams.copy(request.getInputStream(), baos); baos.close(); String data = new String(baos.toByteArray(), StandardCharsets.UTF_8); if (data == null || data.length() == 0) return null; data = data.trim(); if (data.charAt(0) =='{' && data.charAt(data.length() - 1) == '}') try { return new JSONObject(new JSONTokener(data)); } catch (JSONException e) { return null; } return null; } catch (IOException e) { } return null; } public Set<String> getKeys() {
private synchronized void handleRatelimit(Response response, long current) throws IOException { final String retryAfter = response.header("Retry-After"); long delay; if (retryAfter == null) { final JSONObject body = new JSONObject(new JSONTokener(Requester.getBody(response))); delay = body.getLong("retry_after"); } else { delay = Long.parseLong(retryAfter); } resetTime = current + delay; }
JSONObject limitObj = new JSONObject(new JSONTokener(in)); long retryAfter = limitObj.getLong("retry_after");
private ServiceResponse doConnection(ClientConnection connection) throws IOException { Charset charset = connection.getContentType().getCharset(); String mime = connection.getContentType().getMimeType(); //application/javascript, application/octet-stream byte[] b = connection.load(); if (b.length == 0) throw new IOException("response empty"); if (mime.indexOf("javascript") >= 0) { if (b.length > 0 && b[0] == (byte) '[') { JSONArray json = new JSONArray(new JSONTokener(new String(b, charset == null ? StandardCharsets.UTF_8 : charset))); return new ServiceResponse(json); } else { JSONObject json = new JSONObject(new JSONTokener(new String(b, charset == null ? StandardCharsets.UTF_8 : charset))); return new ServiceResponse(json); } } else { // consider this is binary return new ServiceResponse(b); } }
@Override public ServiceResponse serviceImpl(Query call, HttpServletResponse response) { //String indexName, String typeName, final String id, JSONObject object String indexName = call.get("index", ""); String typeName = call.get("type", ""); String id = call.get("id", ""); byte[] object = call.get("object", EMPTY_OBJECT); // this contains the JSON object JSONObject json = new JSONObject(true); if (indexName.length() > 0 && typeName.length() > 0 && id.length() > 0 && object.length > 0) { try { Index index = Data.gridIndex.getElasticIndex(); JSONObject payload = new JSONObject(new JSONTokener(new String(object, StandardCharsets.UTF_8))); IndexFactory factory = index.add(indexName, typeName, id, payload); String url = factory.getConnectionURL(); json.put(ObjectAPIHandler.SUCCESS_KEY, true); if (url != null) json.put(ObjectAPIHandler.SERVICE_KEY, url); } catch (IOException | JSONException e) { json.put(ObjectAPIHandler.SUCCESS_KEY, false); json.put(ObjectAPIHandler.COMMENT_KEY, e.getMessage()); } } else { json.put(ObjectAPIHandler.SUCCESS_KEY, false); json.put(ObjectAPIHandler.COMMENT_KEY, "the request must contain an index, type, id and json object"); } return new ServiceResponse(json); } }
return new Widget(new JSONObject(new JSONTokener(stream))); try (InputStream stream = data) retryAfter = new JSONObject(new JSONTokener(stream)).getLong("retry_after");
try { this.elasticsearchClient.createIndexIfNotExists(indexName, 1 /*shards*/, 1 /*replicas*/); JSONObject mo = new JSONObject(new JSONTokener(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8))); mo = mo.getJSONObject("mappings").getJSONObject("_default_"); this.elasticsearchClient.setMapping(indexName, mo.toString()); Map<String, Object> map = ElasticIndexFactory.this.elasticsearchClient.readMap(indexName, typeName, id); if (map == null) return null; return new JSONObject(map); for (int hitc = 0; hitc < result.size(); hitc++) { Map<String, Object> map = result.get(hitc); list.add(new JSONObject(map));