List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.citrus.sdk.payment.NetbankingOption.java
@Override public String getSavePaymentOptionObject() { JSONObject object = null; try {/*from w ww.j av a2s . c o m*/ object = new JSONObject(); JSONArray paymentOptions = new JSONArray(); JSONObject option = new JSONObject(); option.put("owner", ""); option.put("bank", bankName); option.put("type", "netbanking"); paymentOptions.put(option); object.put("paymentOptions", paymentOptions); object.put("type", "payment"); } catch (JSONException e) { e.printStackTrace(); } return object.toString(); }
From source file:com.shampan.services.VideoService.java
public static String getVideoCategories() { JSONObject categories = new JSONObject(); categories.put("categoryList", vedioObj.getVideoCategories()); return categories.toString(); }
From source file:com.shampan.services.VideoService.java
public static String getVideos(String userId) { JSONObject videos = new JSONObject(); videos.put("videoList", vedioObj.getVideos(userId)); return videos.toString(); }
From source file:com.mercandalli.android.apps.files.common.dialog.DialogCreateArticle.java
public DialogCreateArticle(final Activity activity, final IListener listener) { super(activity); this.mActivity = activity; this.setContentView(R.layout.dialog_create_article); this.setTitle("Create Article"); this.setCancelable(true); this.article_title_1 = (EditText) this.findViewById(R.id.title); this.article_content_1 = (EditText) this.findViewById(R.id.content); this.findViewById(R.id.request).setOnClickListener(new View.OnClickListener() { @Override//from w w w .ja va 2s .c om public void onClick(View v) { SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); String nowAsISO = dateFormatGmt.format(new Date()); JSONObject json = new JSONObject(); try { json.put("type", "article"); json.put("date_creation", nowAsISO); json.put("article_title_1", article_title_1.getText().toString()); json.put("article_content_1", article_content_1.getText().toString()); SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm'Z'", Locale.US); dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC")); nowAsISO = dateFormatGmtTZ.format(new Date()); List<StringPair> parameters = new ArrayList<>(); parameters.add(new StringPair("content", json.toString())); parameters.add(new StringPair("name", "ARTICLE_" + nowAsISO)); new TaskPost(mActivity, Constants.URL_DOMAIN + Config.ROUTE_FILE, new IPostExecuteListener() { @Override public void onPostExecute(JSONObject json, String body) { if (listener != null) { listener.execute(); } } }, parameters, "text/html; charset=utf-8").execute(); } catch (JSONException e) { Log.e(TAG, "DialogCreateArticle: failed to convert Json", e); } DialogCreateArticle.this.dismiss(); } }); DialogCreateArticle.this.show(); }
From source file:com.marpies.ane.facebook.accountkit.functions.LoadPreferencesFunction.java
@Override public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); AIR.log("AccountKit::loadPreference"); final int callbackId = FREObjectUtils.getInt(args[0]); /* User is not logged in, cannot load preferences */ if (AccountKit.getCurrentAccessToken() == null) { dispatchError(callbackId, "User is not logged in, cannot load preferences."); return null; }// w ww .j ava 2 s . c om AccountKit.getAccountPreferences().loadPreferences(new AccountPreferences.OnLoadPreferencesListener() { @Override public void onLoadPreferences(@Nullable Map<String, String> prefs, @Nullable AccountKitError accountKitError) { if (accountKitError != null) { dispatchError(callbackId, accountKitError.getErrorType().getMessage()); } else { AIR.log("AccountKit | successfully loaded preferences"); JSONObject response = new JSONObject(); JSONUtils.addToJSON(response, "callbackId", callbackId); JSONArray preferences = new JSONArray(); for (Map.Entry<String, String> preference : prefs.entrySet()) { preferences.put(preference.getKey()); preferences.put(preference.getValue()); } JSONUtils.addToJSON(response, "preferences", preferences); AIR.dispatchEvent(AccountKitEvent.LOAD_PREFERENCES, response.toString()); } } }); return null; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
@Test public void testPushRemoteRejected() throws Exception { // clone a repo URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); IPath clonePath = getClonePath(workspaceId, project); clone(clonePath);//from w w w. j a v a2 s .c om // get project metadata WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE); // 1st commit JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "1st change"); addFile(testTxt); commitFile(testTxt, "1st change commit", false); // push ServerStatus pushStatus = push(gitRemoteUri, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(IStatus.OK, pushStatus.getSeverity()); // 2nd commit modifyFile(testTxt, "2nd change"); addFile(testTxt); commitFile(testTxt, "2nd change commit", false); FileUtils.delete(new File(gitDir, Constants.DOT_GIT + "/objects/pack/"), FileUtils.RECURSIVE); pushStatus = push(gitRemoteUri, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(IStatus.WARNING, pushStatus.getSeverity()); Status pushResult = Status.valueOf(pushStatus.getMessage()); assertEquals(Status.REJECTED_OTHER_REASON, pushResult); JSONObject jsonResult = pushStatus.toJSON(); if (jsonResult.has("JsonData")) { jsonResult = jsonResult.getJSONObject("JsonData"); } assertTrue(jsonResult.toString(), jsonResult.has("DetailedMessage")); assertTrue(jsonResult.getString("DetailedMessage"), jsonResult.getString("DetailedMessage").matches("^object [\\da-f]+ missing$")); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
static WebRequest getPostGitRemoteRequest(String location, String srcRef, boolean tags, boolean force) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); if (srcRef != null) body.put(GitConstants.KEY_PUSH_SRC_REF, srcRef); body.put(GitConstants.KEY_PUSH_TAGS, tags); body.put(GitConstants.KEY_FORCE, force); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request);//from w w w. j a v a2 s. c om return request; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
static WebRequest getPostGitRemoteRequest(String location, String srcRef, boolean tags, boolean force, String name, String kh, byte[] privk, byte[] pubk, byte[] p) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); body.put(ProtocolConstants.KEY_NAME, name); if (kh != null) body.put(GitConstants.KEY_KNOWN_HOSTS, kh); if (privk != null) body.put(GitConstants.KEY_PRIVATE_KEY, new String(privk)); if (pubk != null) body.put(GitConstants.KEY_PUBLIC_KEY, new String(pubk)); if (p != null) body.put(GitConstants.KEY_PASSPHRASE, new String(p)); if (srcRef != null) body.put(GitConstants.KEY_PUSH_SRC_REF, srcRef); body.put(GitConstants.KEY_PUSH_TAGS, tags); body.put(GitConstants.KEY_FORCE, force); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request);/* www . j ava 2 s .c o m*/ return request; }
From source file:edu.usc.yournextgig.AlbumStubRESTQuery.java
@Override public Response search(String id) { Album album = new Album(); album.setId("http://rdf.freebase.com/ns/m.0g59_v_"); album.setName("So Beautiful or So What"); album.setRating("85"); album.setReleaseDate(new Date(System.currentTimeMillis() + 100000)); Review[] reviews = new Review[2]; reviews[0] = new Review(); reviews[0].setSource("The Telegraph (UK)"); reviews[0].setGrade("100"); reviews[0].setReview(/*from w ww . j ava2s .co m*/ "This album is a musical gumbo: a rich, surprising and ultimately satisfying stew of Simon's folk, rock and pop influences from all over the world."); reviews[1] = new Review(); reviews[1].setSource("Filter"); reviews[1].setGrade("92"); reviews[1].setReview( "Decades beyond the point at which most of his peers peaked, Paul Simon is still discovering new ways of writing and conveying amazing work and discovering beautifully unexpected and often spiritual language, as well as new rhythms, melodies and instrumental textures."); album.getReviews().add(reviews[0]); album.getReviews().add(reviews[1]); JSONObject obj = new JSONObject(album); return Response.ok(obj.toString(), MediaType.APPLICATION_JSON).build(); }
From source file:com.cloverstudio.spika.couchdb.ConnectionHandler.java
public static String getError(InputStream inputStream) throws IOException, JSONException { String error = "Unknown Spika Error: "; String jsonString = getString(inputStream); JSONObject jsonObject = jObjectFromString(jsonString); if (jsonObject.has("message")) { error = jsonObject.getString("message"); } else {/*from w w w . j av a2 s . c o m*/ error += jsonObject.toString(); } return error; }