我已經創建了一個HTTP GET函數,它從我的服務器中檢索響應,並在textview中將其顯示爲JSON。解析爲textview的JSON Android
如何將以下內容轉換爲可由我的textview讀取的字符串。
{"response":"ok"}
這裏是我的HTTP GET請求
public class GetMethodEx {
public String getInternetData() throws Exception {
BufferedReader in = null;
String data = null;
try {
HttpClient client = new DefaultHttpClient();
client.getConnectionManager().getSchemeRegistry().register(getMockedScheme());
URI website = new URI("https://server.com:8443/login?username=hm&password=123");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
response.getStatusLine().getStatusCode();
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) != null) {
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
} finally {
if (in != null) {
try {
in.close();
return data;
} catch (Exception e) {
Log.e("GetMethodEx", e.getMessage());
}
}
}
您在這裏有很多答案。你可以讓所有的東西滿足你的需求。 – intrepidkarthi
@Lyan Rai如果我的回答是幫助你,那麼請接受它。 –