0

I am calling the JSONParser class with the

List<NameValuePair> params = new ArrayList<NameValuePair>(); JSONObject json = jParser.makeHttpRequest(urlServer, "GET", params); 

The JSONParser is this

public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try { if (method == "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(); Log.e("Pasa x aki","ssss"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 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) { 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 return jObj; } } 

My error is in "JSON Parser" because the json object is null. I would like to know what is happening in the server. How can I print the echo from the server?

4
  • The echo of the server is in String json. Commented Oct 26, 2015 at 18:55
  • Off-topic: AFAIK HttpClient is already deprecated for current Android. Commented Oct 26, 2015 at 18:55
  • // return JSON String. No. That is the json object. Commented Oct 26, 2015 at 18:57
  • @greenapps The echo is not in the String json, because the StringBuilder is null, and when I try to convert .toString I get an error Commented Oct 26, 2015 at 21:52

1 Answer 1

1

Try this

HttpEntity entity = response.getEntity(); if (entity != null) { String retSrc = EntityUtils.toString(entity); Log.v("response server ", retSrc); } 
Sign up to request clarification or add additional context in comments.

1 Comment

I would like to do it, but I need 15 of reputation, which I don't have. Sorry

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.