我正在尝试检索堆栈交换 api 的响应,例如 [ http://api.stackexchange.com/2.2/tags?order=desc&sort=popular&site=stackoverflow]
我正在使用以下代码来检索响应
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class RetrieveAllTag {
public static void main(String... args) {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://api.stackexchange.com/2.2/tags?order=desc&sort=popular&site=stackoverflow");
HttpResponse response = null;
try {
response = httpClient.execute(httpGet);
InputStream content = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content,"UTF-8"));
StringBuilder stringBuilder = new StringBuilder();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
stringBuilder.append(inputLine);
stringBuilder.append("\n");
}
System.out.println(stringBuilder.toString());
}
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
finally {
httpClient.getConnectionManager().shutdown();
}
}
}
但我得到的响应是解码后的形式为����n������\f]as��DՊ�I��/�m�(��*Ʃ���Kc���</p>
我发现了类似的问题 [ https://stackoverflow.com/questions/20808901/problems-with-decoding-stack-exchange-api-response],但我没有找到任何问题的答案。
如何解码 api 响应?
提前致谢。