List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.citrus.mobile.RESTclient.java
public JSONObject makePutrequest(JSONObject details) { HttpClient client = new DefaultHttpClient(); HttpPut put = null;// w w w . java 2 s. c o m try { put = new HttpPut(urls.getString(base_url) + urls.getString(type)); } catch (JSONException e) { e.printStackTrace(); } Iterator<String> iterhead = headers.keys(); while (iterhead.hasNext()) { String key = iterhead.next(); try { String value = headers.getString(key); put.addHeader(key, value); } catch (JSONException e) { Log.d("exception", e.toString()); } } try { put.setEntity(new StringEntity(details.toString())); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { response = client.execute(put); } catch (IOException e) { e.printStackTrace(); } return parseResponse(response); }
From source file:com.citrus.mobile.RESTclient.java
public JSONObject postPayment(JSONObject payment) { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = null;// www . jav a 2 s . c o m try { httpPost = new HttpPost(urls.getString(base_url) + urls.getString(type)); } catch (JSONException e) { e.printStackTrace(); return null; } httpPost.setHeader("Content-Type", "application/json"); try { httpPost.setEntity(new StringEntity(payment.toString())); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } try { response = httpClient.execute(httpPost); } catch (IOException e) { e.printStackTrace(); return null; } return parseResponse(response); }
From source file:ecjtu.net.demon.utils.ACache.java
/** * ? JSONObject? /*from w ww . j a v a 2 s. c o m*/ * * @param key * ?key * @param value * ?JSON? */ public void put(String key, JSONObject value) { put(key, value.toString()); }
From source file:ecjtu.net.demon.utils.ACache.java
/** * ? JSONObject? /* w ww . j a v a2 s. c om*/ * * @param key * ?key * @param value * ?JSONObject? * @param saveTime * ??? */ public void put(String key, JSONObject value, int saveTime) { put(key, value.toString(), saveTime); }
From source file:com.hhunj.hhudata.ForegroundService.java
private void handleSearchResults(JSONObject json) { try {/*from w w w.ja v a2s. c o m*/ String s = json.toString(); int count = json.getInt("number_of_results"); if (count > 0) { JSONArray results = json.getJSONArray("search_results"); // SearchBookContentsResult.setQuery(queryTextView.getText().toString()); List<SearchBookContentsResult> items = new ArrayList<SearchBookContentsResult>(0); for (int x = 0; x < count; x++) { JSONObject sr = results.getJSONObject(x); if (sr != null) { items.add(parseResult(sr)); } } // ... // ,... String message = updatedb(items); if (message != "") { // ... Log.w(TAG, "over time err--------"); sendSMS(m_address + ": " + message + "over time"); } //.... m_httpConnect = false; resetForNewQuery(); } else // { // .... // String searchable = json.optString("searchable"); } } catch (JSONException e) { // .... // ... } catch (IllegalArgumentException e2) { // .... // ... int aa = 0; } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
static WebRequest getPutGitConfigRequest(String location, String value) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); body.put(GitConstants.KEY_CONFIG_ENTRY_VALUE, value); WebRequest request = new PutMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request);//from w w w .java 2 s .c o m return request; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
static WebRequest getPostGitConfigRequest(String location, String key, String value) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); body.put(GitConstants.KEY_CONFIG_ENTRY_KEY, key); body.put(GitConstants.KEY_CONFIG_ENTRY_VALUE, value); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request);/* www . j a v a 2s . c o m*/ return request; }
From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java
/** * Sends script to be executed by JavaScript in Web view * @param jsonObj: JSONObject containing script. *///from w w w . ja v a 2 s .co m private void executeScriptInWebView(final JSONObject jsonObj) { if (jsonObj != null) { if (mCobaltIsReady) { mHandler.post(new Runnable() { @Override public void run() { // Line & paragraph separators are not JSON compliant but supported by JSONObject String script = jsonObj.toString().replaceAll("[\u2028\u2029]", ""); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // Since KitKat, messages are automatically urldecoded when received from the web. encoding them to fix this. script = script.replaceAll("%", "%25"); } String url = "javascript:cobalt.execute(" + script + ");"; mWebView.loadUrl(url); } }); } else { if (Cobalt.DEBUG) Log.i(Cobalt.TAG, TAG + " - executeScriptInWebView: adding message to queue: " + jsonObj); mWaitingJavaScriptCallsQueue.add(jsonObj); } } else if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - executeScriptInWebView: jsonObj is null!"); }
From source file:org.account.LoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w.ja va 2 s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); JSONObject jsonResponse = new JSONObject(); PrintWriter out = response.getWriter(); String email = request.getParameter("email"); String password = request.getParameter("password"); if (Login.checkUser(email, password)) { int retid = Login.findUserId(email, password); jsonResponse.put("id", retid); jsonResponse.put("username", Login.findUsernamebyId(retid)); out.write(jsonResponse.toString()); out.flush(); } else { jsonResponse.put("id", "Login failed"); jsonResponse.put("username", "nil"); out.write(jsonResponse.toString()); out.flush(); } }
From source file:ch.icclab.cyclops.persistence.client.InfluxDBClient.java
public TSDBData getData(String query) { JSONArray resultArray;/*from ww w .j a v a2s . c o m*/ JSONObject resultObj; TSDBData dataObj = null; Representation output; ObjectMapper mapper = new ObjectMapper(); Client client = new Client(Protocol.HTTP); ClientResource cr = new ClientResource(url); cr.addQueryParameter("q", query); cr.addQueryParameter("u", username); cr.addQueryParameter("p", password); cr.get(MediaType.APPLICATION_JSON); output = cr.getResponseEntity(); try { resultArray = new JSONArray(output.getText()); if (!resultArray.isNull(0)) { resultObj = new JSONObject(); resultObj = (JSONObject) resultArray.get(0); dataObj = mapper.readValue(resultObj.toString(), TSDBData.class); } } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return dataObj; }