Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>for parsing the data I use the following class</p> <p>JsonParser.java</p> <pre><code>public class JSONParser { InputStream is = null; JSONObject jObj = null; String json = ""; public JSONParser() { } // function get json from url // by making HTTP POST or GET method public JSONObject makeHttpRequest(String url, String method, List&lt;NameValuePair&gt; params) { // Making HTTP request try { // check for request method if (method == "POST") { // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "UTF-8"), 8); StringBuilder sb = new StringBuilder(""); Log.d("reader value in json parser", reader.toString()); String line = ""; while ((line = reader.readLine()) != null) { Log.d("line in JsonParser", line); sb.append(line + "\n"); } is.close(); json = sb.toString(); Log.d("Json value", json); } catch (Exception e) { Log.d("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); json = ""; } catch (JSONException e) { Log.d("JSON Parser", "Error parsing data " + e.toString()); } return jObj; } } </code></pre> <p>now in your activity try to pass a url like this </p> <pre><code>String url="place your url here"; JSONParser jparser= new JSONParser(); params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("tag", "getcategory")); params.add(new BasicNameValuePair("username", username.getText().toString())); params.add(new BasicNameValuePair("password", password.getText().toString())); JSONObject jobj= jparser.makeHttpRequest(url, "POST", params); </code></pre> <p>//now here retrieve the data from json as:</p> <pre><code>String success= jobj.get("success"); </code></pre> <p>Hope this helps!</p> <p>also in your php file you have to use the <code>json_encode</code> function before <code>echo</code> ! </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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