我想如下執行該JSON電話:JSON調用無效(Android)
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=insouciant&sl=en&tl=en");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = null;
try{
responseBody = client.execute(get, responseHandler);
}catch(Exception ex) {
ex.printStackTrace();
}
JSONObject jsonObject = null;
JSONParser parser=new JSONParser();
try {
Object obj = parser.parse(responseBody);
jsonObject=(JSONObject)obj;
System.out.println("JSONRESPONSE getCardsFromTagNames="+jsonObject);
}catch(Exception ex){
Log.v("TEST","Exception: " + ex.getMessage());
}
}
});
不幸的是,返回的結果爲空。我究竟做錯了什麼?謝謝!
剛擡起頭,任何網絡I/O應該是在一個單獨的線程中完成的,而不是在用戶界面線。 – SeanPONeil 2012-03-05 18:50:54