List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.esri.squadleader.model.GeoPackageReader.java
private static List<Layer> getTablesAsLayers(List<GeopackageFeatureTable> tables, Set<Geometry.Type> types, Renderer renderer) {/*w w w .j a v a2s. c o m*/ List<Layer> layers = new ArrayList<Layer>(tables.size()); for (GeopackageFeatureTable table : tables) { if (types.contains(table.getGeometryType())) { final FeatureLayer layer = new FeatureLayer(table); JSONObject jsonObject = new JSONObject(); JSONArray fieldsArray = new JSONArray(); try { for (Field field : table.getFields()) { fieldsArray.put(new JSONObject(Field.toJson(field))); } jsonObject.put("fields", fieldsArray); LayerServiceInfo layerInfo = LayerServiceInfo .fromJson(new JsonFactory().createJsonParser(jsonObject.toString())); layer.getPopupInfo(0).setLayer(layerInfo); } catch (Exception e) { Log.e(TAG, "Could not create LayerServiceInfo for FeatureLayer for table " + table.getTableName(), e); } layer.setRenderer(renderer); layer.setName(table.getTableName()); layers.add(layer); } } return layers; }
From source file:net.dv8tion.jda.core.requests.GuildLock.java
public void queue(long guildId, JSONObject event) { if (isLocked(guildId)) { LOG.debug("Queueing up event for guild with id " + guildId + ": " + event.toString()); cache.get(guildId).add(event);/*from www. j a v a 2 s .c om*/ } }
From source file:org.idaxiang.elephant.api.user.UserApi.java
public static UserModel getUser(String uid) { BaseParameters params = new WeiboParameters(); params.put("uid", uid); try {// w ww. j a va 2 s. c o m JSONObject json = request(Constants.USER_SHOW, params, HTTP_GET); UserModel user = new Gson().fromJson(json.toString().replaceAll("-Weibo", ""), UserModel.class); return user; } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Failed to fetch user info from net: " + e.getClass().getSimpleName()); } return null; } }
From source file:org.idaxiang.elephant.api.user.UserApi.java
public static UserModel getUserByName(String name) { WeiboParameters params = new WeiboParameters(); params.put("screen_name", name); try {//from ww w . ja v a 2 s . c o m JSONObject json = request(Constants.USER_SHOW, params, HTTP_GET); UserModel user = new Gson().fromJson(json.toString().replaceAll("-Weibo", ""), UserModel.class); return user; } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Failed to fetch user info from net: " + e.getClass().getSimpleName()); } return null; } }
From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java
/** * Gets the last completed thermostat job. * //from w w w . j a v a2s. c o m * @param thermostatId * the thermostat id * @return the last completed thermostat job * @see com.ecofactor.qa.automation.algorithm.service.DataService#getLastCompletedThermostatJob(java.lang.Integer) */ @Override public ThermostatJob getLastCompletedThermostatJob(Integer thermostatId) { ThermostatJob thermostatJob = null; JSONArray jsonArray = getJobData(thermostatId); for (int i = 0; i < jsonArray.length(); i++) { try { thermostatJob = new ThermostatJob(); Calendar calendar = DateUtil.getUTCCalendar(); JSONObject jsonObj = jsonArray.getJSONObject(i); thermostatJob.setThermostatId(thermostatId); thermostatJob.setJobData(jsonObj.toString()); thermostatJob.setStartDate(calendar); thermostatJob.setEndDate(calendar); thermostatJob.setJobType("SPO"); thermostatJob.setAlgorithmId(190); thermostatJob.setJobStatus(ThermostatJob.Status.PROCESSED); } catch (Exception e) { e.printStackTrace(); } } return thermostatJob; }
From source file:org.searsia.web.Search.java
private void logQuery(String resourceid, String query) { JSONObject r = new JSONObject(); r.put("time", df.format(new Date())); if (resourceid != null) r.put("resourceid", resourceid); r.put("query", query); LOGGER.info(r.toString()); }
From source file:org.searsia.web.Search.java
private void logWarning(String message) { JSONObject r = new JSONObject(); r.put("time", df.format(new Date())); r.put("warning", message); LOGGER.warn(r.toString()); }
From source file:org.servalproject.maps.bridge.json.BasicJsonMaker.java
/** * take a table row as represented by a ContentValues object and return a JSON encoded string * @param values a ContentValues object representing a row in the database * @return a JSON encoded string of the data * @throws JSONException if the encode to JSON fails */// www.j a va2 s . c o m public static String makePoiJson(ContentValues values) throws JSONException { String mResults = null; Entry<String, Object> mEntry = null; JSONObject mJsonObject = new JSONObject(); Set<Entry<String, Object>> mValueSet = values.valueSet(); Iterator<Entry<String, Object>> mIterator = mValueSet.iterator(); while (mIterator.hasNext()) { mEntry = mIterator.next(); mJsonObject.put(mEntry.getKey(), mEntry.getValue()); } mResults = mJsonObject.toString(); return mResults; }
From source file:com.farru.android.volley.toolbox.JsonObjectRequest.java
/** * Creates a new request./*w w w . j a va 2s.co m*/ * @param method the HTTP method to use * @param url URL to fetch the JSON from * @param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and * indicates no parameters will be posted along with request. * @param listener Listener to receive the JSON response * @param errorListener Error listener, or null to ignore errors. */ public JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) { super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, errorListener); }
From source file:io.s4.client.Driver.java
/** * Establish a connection to the adapter. Upon success, this enables the * client to send and receive events. The client must first be initialized. * Otherwise, this operation will fail.//from w ww .j av a 2 s . c o m * * @see #init() * * @return true if and only if a connection was successfully established. * @throws IOException * if the underlying TCP/IP socket throws an exception. */ public boolean connect() throws IOException { if (!state.isInitialized()) { // must first be initialized if (debug) { System.err.println("Not initialized."); } return false; } else if (state.isConnected()) { // nothing to do if already connected. return true; } String message = null; try { // constructing connect message JSONObject json = new JSONObject(); json.put("uuid", uuid); json.put("readMode", readMode.toString()); json.put("writeMode", writeMode.toString()); if (readInclude != null) { // stream inclusion json.put("readInclude", new JSONArray(readInclude)); } if (readExclude != null) { // stream exclusion json.put("readExclude", new JSONArray(readExclude)); } message = json.toString(); } catch (JSONException e) { if (debug) { System.err.println("error constructing connect message: " + e); } return false; } try { // send the message this.sock = new Socket(hostname, port); this.io = new ByteArrayIOChannel(sock); io.send(message.getBytes()); // get a response byte[] b = io.recv(); if (b == null || b.length == 0) { if (debug) { System.err.println("empty response from adapter during connect."); } return false; } String response = new String(b); JSONObject json = new JSONObject(response); String s = json.optString("status", "unknown"); // does it look OK? if (s.equalsIgnoreCase("ok")) { // done connecting state = State.Connected; return true; } else if (s.equalsIgnoreCase("failed")) { // server has failed the connect attempt if (debug) { System.err.println("connect failed by adapter. reason: " + json.optString("reason", "unknown")); } return false; } else { // unknown response. if (debug) { System.err.println("connect failed by adapter. unrecongnized response: " + response); } return false; } } catch (Exception e) { // clean up after error... if (debug) { System.err.println("error during connect: " + e); e.printStackTrace(); } if (this.sock.isConnected()) { this.sock.close(); } return false; } }