List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.chess.genesis.net.SocketClient.java
public synchronized void write(final JSONObject data) throws IOException { connect();/*from ww w . j a v a2s. com*/ final String str = data.toString() + '\n'; output.write(str.getBytes()); }
From source file:com.chess.genesis.net.SocketClient.java
public void logError(final Context context, final Exception trace, final JSONObject json) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); final FileLogger logger = new FileLogger(trace); logger.addItem("NetActive", (netInfo != null) ? netInfo.isConnected() : null); logger.addItem("isConnected", socket.isConnected()); logger.addItem("isLoggedIn", isLoggedin); logger.addItem("loginHash", loginHash); logger.addItem("request", json.toString()); logger.write();//from w ww . j a va2 s . c o m }
From source file:edu.mit.mobile.android.locast.sync.SyncEngine.java
/** * Uploads any unpublished casts./*from ww w . jav a 2 s.c om*/ * * This is the method that does all the hard work. * * @param toSync * @param provider * @param syncMap * @param syncResult * @return the number of casts uploaded. * @throws JSONException * @throws NetworkProtocolException * @throws IOException * @throws NoPublicPath * @throws RemoteException * @throws OperationApplicationException * @throws SyncException * @throws InterruptedException */ private int uploadUnpublished(Uri toSync, Account account, ContentProviderClient provider, SyncMap syncMap, HashMap<String, SyncEngine.SyncStatus> syncStatuses, SyncResult syncResult) throws JSONException, NetworkProtocolException, IOException, NoPublicPath, RemoteException, OperationApplicationException, SyncException, InterruptedException { int count = 0; final String type = provider.getType(toSync); final boolean isDir = type.startsWith(CONTENT_TYPE_PREFIX_DIR); final Cursor uploadMe = provider.query(toSync, null, SELECTION_UNPUBLISHED, null, null); if (uploadMe == null) { throw new SyncException("could not query " + toSync); } final int idCol = uploadMe.getColumnIndex(JsonSyncableItem._ID); try { for (uploadMe.moveToFirst(); !uploadMe.isAfterLast(); uploadMe.moveToNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } final long id = uploadMe.getLong(idCol); final Uri localUri = isDir ? ContentUris.withAppendedId(toSync, id) : toSync; final String postUri = MediaProvider.getPostPath(mContext, localUri); Intent intent = new Intent(SYNC_STATUS_CHANGED); intent.putExtra(EXTRA_SYNC_STATUS, "castBegin"); intent.putExtra(EXTRA_SYNC_ID, id); mContext.sendStickyBroadcast(intent); try { final JSONObject jo = JsonSyncableItem.toJSON(mContext, localUri, uploadMe, syncMap); if (DEBUG) { Log.d(TAG, "uploading " + localUri + " to " + postUri); } // Upload! Any non-successful responses are handled by // exceptions. final HttpResponse res = mNetworkClient.post(postUri, jo.toString()); long serverTime; try { serverTime = getServerTime(res); // We should never get a corrupted date from the server, // but if it does happen, // using the local time is a sane fallback. } catch (final DateParseException e) { serverTime = System.currentTimeMillis(); } // newly-created items return the JSON serialization of the // object as the server // knows it, so the local database needs to be updated to // reflect that. final JSONObject newJo = NetworkClient.toJsonObject(res); try { final SyncStatus ss = loadItemFromJsonObject(newJo, syncMap, serverTime); // update immediately, so that any cancellation or // interruption of the sync // keeps the local state in sync with what's on the // server final int updates = provider.update(localUri, ss.remoteCVs, null, null); final String locUriString = localUri.toString(); if (updates == 1) { ss.state = SyncState.NOW_UP_TO_DATE; ss.local = localUri; // ensure that it's findable by local URI too syncStatuses.put(locUriString, ss); syncMap.onPostSyncItem(mContext, account, ss.local, ss.remoteJson, true); count++; syncResult.stats.numUpdates++; } else { Log.e(TAG, "error updating " + locUriString); syncResult.stats.numSkippedEntries++; } syncResult.stats.numEntries++; } catch (final JSONException e) { if (DEBUG) { Log.e(TAG, "result was " + newJo.toString()); } throw e; } } finally { intent = new Intent(SYNC_STATUS_CHANGED); intent.putExtra(EXTRA_SYNC_STATUS, "castEnd"); intent.putExtra(EXTRA_SYNC_ID, id); mContext.sendStickyBroadcast(intent); } } } finally { uploadMe.close(); } return count; }
From source file:com.shampan.services.PageService.java
public static String getCategorySubCategory() { JSONObject json = new JSONObject(); json.put("categoryList", pageObject.getCategories()); json.put("subCategoryList", pageObject.getSubCategories()); return json.toString(); }
From source file:com.shampan.services.PageService.java
public static String getTimelinePhotos(String pageId, String userId) { JSONObject json = new JSONObject(); json.put("pageInfo", pageObject.getPageInfo(pageId)); json.put("pageMemberInfo", pageObject.getMemeberInfo(pageId, userId)); json.put("photoList", pageObject.getTimelinePhotos(pageId)); return json.toString(); }
From source file:com.shampan.services.PageService.java
public static String getAlbums(String pageId) { JSONObject albums = new JSONObject(); albums.put("albumList", pageObject.getAlbums(pageId)); return albums.toString(); }
From source file:com.shampan.services.PageService.java
public static String getPhotos(String userId, String mappingId, String albumId) { JSONObject photos = new JSONObject(); photos.put("albumInfo", pageObject.getAlbum(userId, mappingId, albumId)); photos.put("photoList", pageObject.getPhotos(mappingId, albumId)); return photos.toString(); }
From source file:com.shampan.services.PageService.java
public static String getPageInfo(String pageId, String userId) { JSONObject json = new JSONObject(); json.put("pageInfo", pageObject.getPageInfo(pageId)); json.put("pageMemberInfo", pageObject.getMemeberInfo(pageId, userId)); return json.toString(); }
From source file:org.digitalcampus.oppia.application.Tracker.java
public void saveTracker(int courseId, String digest, JSONObject data, boolean completed) { // add tracker UUID UUID guid = java.util.UUID.randomUUID(); try {//from w ww . j a v a 2 s.co m data.put("uuid", guid.toString()); } catch (JSONException e) { e.printStackTrace(); } DbHelper db = new DbHelper(this.ctx); db.insertTracker(courseId, digest, data.toString(), completed); DatabaseManager.getInstance().closeDatabase(); }
From source file:com.cloudcontrolled.api.response.normalize.DeploymentNormalizer.java
/** {@inheritDoc} */ @Override/*from w ww . j av a 2 s. co m*/ public String normalize(String jsonResponse) throws Exception { JSONObject body = new JSONObject(jsonResponse); Map<String, JSONObject> layout = new HashMap<String, JSONObject>(); layout.put("deployment", body); JSONObject deployment = new JSONObject(layout); return deployment.toString(); }