I'm having some issues with my android application. I currently have a String with my JSON in it.
HttpResponse response = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.brocksportfolio.com/GetPendingRequests.php");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("Username", "Brock"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
response = httpClient.execute(httpPost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (IOException e) {
e.printStackTrace();
}
String jsonStr = response.toString();
I am trying to initialize a JSONObject with that string in it like so.
JSONObject jsonObj = new JSONObject(jsonString);
I am getting this error.
org.json.JSONException: Value org.apache.http.message.BasicHttpResponse@3526f881 of type java.lang.String cannot be converted to JSONObject
I believe the reason for this error is because I am converting an HTTPPostResponse to a string and then trying to pass that string through to a JSONObject but i'm just really not sure how to fix it. Thanks for the help!