我想解析我的網站序列化的JSON數據:http://demos.brianbuikema.com/apps/soa_services/employees?format=JSON 但我的結果,我回來的是該網站的源代碼:http://demos.brianbuikema.com/apps/soa_services/employees? 因此,某處我的參數format = JSON將被刪除。但我不知道如何在哪裏Httpget刪除參數
這是我的代碼不介意log.d,它只是爲我當我調試調試。 `
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet("http://demos.brianbuikema.com/apps/soa_services/employees?format=JSON");
String result = null;
try {
// execute the request
Log.d("buh", "2aa");
HttpResponse response = httpclient.execute(httpget);
Log.d("buh", "2a");
// Get hold of the response entity
HttpEntity entity = response.getEntity();
// If the response does not enclose an entity, there is no need
// to worry about connection release
Log.d("buh", "2b");
if (entity != null) {
// A Simple Response Read
Log.d("buh", "2c");
InputStream instream = entity.getContent();
result = convertStreamToString(instream);
Log.d("buh",result);
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
private static String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the
* BufferedReader.readLine() method. We iterate until the BufferedReader
* return null which means there's no more data to read. Each line will
* appended to a StringBuilder and returned as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8192);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
} `
優秀的答案! – 2014-02-19 03:02:07