Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i wanted to put some comment but i should have at list 50 reputation!!! so i should give my answer here... i had same problem with json object. use "GET" method instead of "POST". try it...</p> <p>USE THIS JSON PARSER</p> <pre><code>public class JSONParser extends Activity{ static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } // function get json from url // by making HTTP POST or GET mehtod 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) { Log.e("JSON PARSER", "GET OR POST"); Toast.makeText(getApplicationContext(), "Something is wrong with network!", Toast.LENGTH_LONG).show(); json=""; create_JSon_Object(); } catch (ClientProtocolException e) { Toast.makeText(getApplicationContext(), "Something is wrong with network!", Toast.LENGTH_LONG).show(); Log.e("JSON PARSER", "GET OR POST"); json=""; return create_JSon_Object(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Something is wrong with network!", Toast.LENGTH_LONG).show(); Log.e("JSON PARSER IO ERROR", "GET OR POST"); json=""; return create_JSon_Object(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "Something is wrong with network!", Toast.LENGTH_LONG).show(); Log.e("JSON PARSER Buffer Error", "Error converting result "); json=""; return create_JSon_Object(); } return create_JSon_Object(); } private JSONObject create_JSon_Object() { // try parse the string to a JSON object try { //jObj = new JSONObject(json); jObj = new JSONObject(json); } catch (JSONException e) { Toast.makeText(getApplicationContext(), "Something is wrong with network!", Toast.LENGTH_LONG).show(); Log.e("JSON Parser", "Error parsing data " + e.toString()); return jObj; } // return JSON String return jObj; } } </code></pre>
    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. 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