List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.facebook.login.LoginLogger.java
public void logCompleteLogin(String loginRequestId, Map<String, String> loggingExtras, LoginClient.Result.Code result, Map<String, String> resultExtras, Exception exception) { Bundle bundle = newAuthorizationLoggingBundle(loginRequestId); if (result != null) { bundle.putString(EVENT_PARAM_LOGIN_RESULT, result.getLoggingValue()); }// w w w . j av a2s . c o m if (exception != null && exception.getMessage() != null) { bundle.putString(EVENT_PARAM_ERROR_MESSAGE, exception.getMessage()); } // Combine extras from the request and from the result. JSONObject jsonObject = null; if (loggingExtras.isEmpty() == false) { jsonObject = new JSONObject(loggingExtras); } if (resultExtras != null) { if (jsonObject == null) { jsonObject = new JSONObject(); } try { for (Map.Entry<String, String> entry : resultExtras.entrySet()) { jsonObject.put(entry.getKey(), entry.getValue()); } } catch (JSONException e) { } } if (jsonObject != null) { bundle.putString(EVENT_PARAM_EXTRAS, jsonObject.toString()); } appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_COMPLETE, null, bundle); }
From source file:com.facebook.login.LoginLogger.java
public void logAuthorizationMethodComplete(String authId, String method, String result, String errorMessage, String errorCode, Map<String, String> loggingExtras) { Bundle bundle;/* w w w . ja v a2 s .c om*/ bundle = LoginLogger.newAuthorizationLoggingBundle(authId); if (result != null) { bundle.putString(LoginLogger.EVENT_PARAM_LOGIN_RESULT, result); } if (errorMessage != null) { bundle.putString(LoginLogger.EVENT_PARAM_ERROR_MESSAGE, errorMessage); } if (errorCode != null) { bundle.putString(LoginLogger.EVENT_PARAM_ERROR_CODE, errorCode); } if (loggingExtras != null && !loggingExtras.isEmpty()) { JSONObject jsonObject = new JSONObject(loggingExtras); bundle.putString(LoginLogger.EVENT_PARAM_EXTRAS, jsonObject.toString()); } bundle.putString(EVENT_PARAM_METHOD, method); appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_METHOD_COMPLETE, null, bundle); }
From source file:net.dv8tion.jda.core.requests.RestAction.java
/** * Creates a new RestAction instance/*from w w w . j a va 2s .c o m*/ * * @param api * The current JDA instance * @param route * The {@link net.dv8tion.jda.core.requests.Route.CompiledRoute Route.CompiledRoute} * to be used for rate limit handling * @param data * The data that should be sent to the specified route. (can be null) */ public RestAction(JDA api, Route.CompiledRoute route, JSONObject data) { this(api, route, data == null ? null : RequestBody.create(Requester.MEDIA_TYPE_JSON, data.toString())); this.rawData = data; }
From source file:net.dv8tion.jda.core.requests.RestAction.java
protected RequestBody getRequestBody(JSONObject object) { this.rawData = object; return object == null ? null : RequestBody.create(Requester.MEDIA_TYPE_JSON, object.toString()); }
From source file:org.onepf.oms.data.SkuDetails.java
public String toJson() { JSONObject o = new JSONObject(); try {// w w w. j ava 2 s. c o m o.put("productId", _sku); o.put("type", _type); o.put("price", _price); o.put("title", _title); o.put("description", _description); } catch (JSONException e) { Log.e(BillingApplication.TAG, "Couldn't serialize " + getClass().getSimpleName()); return ""; } return o.toString(); }
From source file:com.ledger.android.u2f.bridge.MainActivity.java
private String createClientData(U2FContext context) { try {/*from w ww. ja va 2 s .c o m*/ JSONObject clientData = new JSONObject(); clientData.put(TAG_JSON_TYP, (context.isSign() ? SIGN_RESPONSE_TYP : REGISTER_RESPONSE_TYP)); clientData.put(TAG_JSON_CHALLENGE, Base64.encodeToString(context.getChallenge(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); clientData.put(TAG_JSON_ORIGIN, context.getAppId()); clientData.put(TAG_JSON_CID_PUBKEY, CID_UNAVAILABLE); return clientData.toString(); } catch (Exception e) { Log.e(TAG, "Error encoding client data"); return null; } }
From source file:com.ledger.android.u2f.bridge.MainActivity.java
private String createU2FResponseSign(U2FContext context, byte[] signature) { try {//from w w w . j a v a2 s. c o m JSONObject response = new JSONObject(); response.put(TAG_JSON_TYPE, SIGN_RESPONSE_TYPE); response.put(TAG_JSON_REQUESTID, context.getRequestId()); JSONObject responseData = new JSONObject(); responseData.put(TAG_JSON_KEYHANDLE, Base64.encodeToString(context.getChosenKeyHandle(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); responseData.put(TAG_JSON_SIGNATUREDATA, Base64.encodeToString(signature, 0, signature.length - 2, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); String clientData = createClientData(context); responseData.put(TAG_JSON_CLIENTDATA, Base64.encodeToString(clientData.getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); response.put(TAG_JSON_RESPONSEDATA, responseData); return response.toString(); } catch (Exception e) { Log.e(TAG, "Error encoding request"); return null; } }
From source file:com.ledger.android.u2f.bridge.MainActivity.java
private String createU2FResponseRegister(U2FContext context, byte[] registerResponse) { try {/* w ww . j a v a 2 s. co m*/ JSONObject response = new JSONObject(); response.put(TAG_JSON_TYPE, REGISTER_RESPONSE_TYPE); response.put(TAG_JSON_REQUESTID, context.getRequestId()); JSONObject responseData = new JSONObject(); responseData.put(TAG_JSON_REGISTRATIONDATA, Base64.encodeToString(registerResponse, 0, registerResponse.length - 2, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); responseData.put(TAG_JSON_VERSION, VERSION_U2F_V2); String clientData = createClientData(context); responseData.put(TAG_JSON_CLIENTDATA, Base64.encodeToString(clientData.getBytes("UTF-8"), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING)); response.put(TAG_JSON_RESPONSEDATA, responseData); return response.toString(); } catch (Exception e) { Log.e(TAG, "Error encoding request"); return null; } }
From source file:de.decoit.visa.http.ajax.handlers.RemoveVLANHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.info(he.getRequestURI().toString()); // Get the URI of the request and extract the query string from it QueryString queryParameters = new QueryString(he.getRequestURI()); // Create StringBuilder for the response String response = null;// w ww . j a v a 2 s .c o m // Check if the query parameters are valid for this handler if (this.checkQueryParameters(queryParameters)) { // Any exception thrown during object creation will cause // failure of the AJAX request try { JSONObject rv = new JSONObject(); TEBackend.TOPOLOGY_STORAGE.removeVLAN(queryParameters.get("locname").get()); rv.put("status", AJAXServer.AJAX_SUCCESS); rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON()); // Set the HTTP response to the identifier string of the new // component response = rv.toString(); } catch (Throwable ex) { TEBackend.logException(ex, log); try { // Synchronize the topology with the RDF model to resolve // any errors caused by the caught exception TEBackend.RDF_MANAGER.syncTopologyToRDF(); JSONObject rv = new JSONObject(); rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION); rv.put("type", ex.getClass().getSimpleName()); rv.put("message", ex.getMessage()); rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON()); response = rv.toString(); } catch (Throwable e) { // Exception during synchronization, the model may have been // corrupted so the whole backend was cleared JSONObject rv = new JSONObject(); try { rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION_UNRESOLVED); rv.put("topology", TEBackend.TOPOLOGY_STORAGE.genTopologyJSON()); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } } } else { // Missing or malformed query string, set response to error code JSONObject rv = new JSONObject(); try { rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS); } catch (JSONException exc) { /* Ignore */ } response = rv.toString(); } // Send the response sendResponse(he, response); }
From source file:com.browseengine.bobo.server.protocol.BrowseJSONSerializer.java
public static String serialize(BrowseResult result) throws JSONException { JSONObject obj = new JSONObject(); if (result != null) { obj.put("time", ((double) result.getTime()) / 1000.0); obj.put("hitCount", result.getNumHits()); obj.put("totalDocs", result.getTotalDocs()); // serialize choices JSONObject choices = new JSONObject(); Set<Entry<String, FacetAccessible>> facetAccessors = result.getFacetMap().entrySet(); for (Entry<String, FacetAccessible> entry : facetAccessors) { JSONObject choiceObject = new JSONObject(); JSONArray choiceValArray = new JSONArray(); choiceObject.put("choicelist", choiceValArray); int k = 0; String name = entry.getKey(); FacetAccessible facets = entry.getValue(); List<BrowseFacet> facetList = facets.getFacets(); for (BrowseFacet facet : facetList) { JSONObject choice = new JSONObject(); choice.put("val", facet.getValue()); choice.put("hits", facet.getHitCount()); choiceValArray.put(k++, choice); }/*from w ww .j av a2s. c o m*/ choices.put(name, choiceObject); } obj.put("choices", choices); JSONArray hitsArray = new JSONArray(); BrowseHit[] hits = result.getHits(); if (hits != null && hits.length > 0) { for (int i = 0; i < hits.length; ++i) { hitsArray.put(i, serializeHits(hits[i])); } } obj.put("hits", hitsArray); // serialize documents } return obj.toString(); }