Reputation: 119
I am getting an exception:
java.lang.Boolean
cannot be converted toJSONObject
How can I remove this exception?
HttpGet request = new
HttpGet("http://xxxxxxxxxxxx/REST/MobileService.svcisApproved?DeviceID=123");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
String changeTIDRec = EntityUtils.toString(responseEntity);
JSONObject jsonResponse = new JSONObject(changeTIDRec);
Upvotes: 1
Views: 2970
Reputation: 22948
Why don't you use Gson:
String test = "test string";
Gson gson = new Gson();
gson.toJson(test);
Upvotes: 0
Reputation: 16120
You need this method:
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
// Log.e(TAG, e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
} finally {
try {
is.close();
} catch (IOException e) {
// Log.e(TAG, e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
return sb.toString();
}
and it is used like:
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
Upvotes: 1