2 it kun IT_kun 于 2013.05.30 11:16 提问

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
IT_kun   2013.06.15 09:46

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

suannai0314
suannai0314 贴下解决方案然后采纳为答案呗?
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!