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:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp