Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use following method for generating json Object </p> <pre><code>private JSONObject getConvertedinJson(String email, String password) { JSONObject object = new JSONObject(); try { object.put("email", email); object.put("password", password); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return object; } </code></pre> <p>after that use following method for posting json object on url</p> <pre><code> public JSONObject getJSONFromUrl(String url, JSONObject jObj) { // Making HTTP request try { // Default Http Client DefaultHttpClient httpClient = new DefaultHttpClient(); // Http Post Header HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(jObj.toString()); httpPost.setEntity(se); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); // Execute Http Post Request HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /* * To convert the InputStream to String we use the * BufferedReader.readLine() method. We iterate until the BufferedReader * return null which means there's no more data to read. Each line will * appended to a StringBuilder and returned as String. */ try { // Getting Server Response BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; // Reading Server Response while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String Log.e("JSON Parser", jObj.toString()); return jObj; } </code></pre> <p>Now Use following statement to get json response.</p> <pre><code>JSONObject jsonObject = getJSONFromUrl( "www.url.com/api", getConvertedinJson("test@test.com", "123456")); </code></pre> <p>Now you can easily Deserialize jsonObject according to need.</p> <p><strong>Note: Your Post Data must be Json Object. As I have seen webdata={"email":"test@test.com","password":"123456"} is not jsonObject here json Object is only {"email":"test@test.com","password":"123456"}</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload