IT_kun 2013-05-30 03:16 采纳率: 0%
浏览 2243

android 百度翻译开发

android 百度翻译开发,这段代码在android 3.0以下版本是可以执行的,在4.0上就只能执行到HttpResponse response = httpClient.execute(httpPost); 求解

try{
                            HttpEntity httpEntity = new UrlEncodedFormEntity(postParams,HTTP.UTF_8);
                            HttpPost httpPost = new HttpPost(urlApi);
                            HttpClient httpClient = new DefaultHttpClient();
                            httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
                            httpPost.setEntity(httpEntity);
                            HttpResponse response = httpClient.execute(httpPost);
                        if(response.getStatusLine().getStatusCode()==200){ 
                           String strResult=EntityUtils.toString(response.getEntity());
                           jsonObject =new JSONObject(strResult);
                           JSONArray json = jsonObject.getJSONArray("trans_result");
                           String showMessage="";
                           for(int i =0;i<json.length();i++){
                           JSONObject data =(JSONObject)json.get(i);
                           showMessage +=data.getString("dst");                
                           }
                           ToText.setText(showMessage);                         
                        }else{ 
                       ToText.setText("Error Response"+response.getStatusLine().toString()); 
                       } 
                        }
                        catch(Exception e){
                            Log.i("BaiduTrans.java", "百度翻译异常");
                        }
  • 写回答

1条回答 默认 最新

  • IT_kun 2013-06-15 01:46
    关注

    大家好 ,问题我已经解决了

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算