我创建了一个从服务器提取数据的 jsonobject,但它仅适用于小于 3 的 android 版本(旧版本)。使它适用于所有版本的代码是什么?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DefaultHttpClient client;
client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://saurabhgoyal.comoj.com/json_test.php");
HttpResponse r;
try {
r = client.execute(get);
HttpEntity e = r.getEntity();
InputStream is=e.getContent();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader reader=new BufferedReader(isr);
String results=reader.readLine();
Toast.makeText(this, results, Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
Toast.makeText(this, "failure", Toast.LENGTH_SHORT).show();
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}