爱问知识人 爱问教育 医院库

获取天气API信息乱码怎么?

首页

获取天气API信息乱码怎么?

获取天气API信息乱码怎么办

提交回答

全部答案

    2014-06-18 16:27:26
  •   解决办法
    第一步:b[]=htmlStr。getBytes("ISO-8859-1"); htmlStr=new String(b);把ISO-8859-1换成utf-8
    第二步:右键项目----》Properties(最后一个)---》Resource(第一个选项)-----》Other选择utf-8
    给好评呦!!! 
    我都写出来了测试过了
    java代码
    public class abc {
        
        public static void main(String[] args) throws ClientProtocolException, IOException {
            getInfo();
        }
    public static void getInfo() throws ClientProtocolException, IOException{
    String htmlStr = getHtmlFile("http://www。
      weather。com。cn/data/cityinfo/101010100。html"); try{ //ISO-8859-1 city":"北京","cityid":"101010100","temp1":"25�?,"temp2":"17�?,"weather":"小到中雨转阵�?, //utf-8 {"weatherinfo":{"city":"鍖椾�?,"cityid":"101010100","temp1":"25鈩�,"temp2":"17鈩�,"weather":"灏忓埌涓洦杞�?���? byte b[]=htmlStr。
      getBytes("utf-8"); htmlStr=new String(b); } catch(Exception e) { e。printStackTrace(); e。getMessage(); } System。
      out。println(htmlStr); } public static String getHtmlFile(String url) throws ClientProtocolException, IOException{ String result=""; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; HttpGet httpGet = new HttpGet(url); HttpEntity httpEntity; InputStream is = null; //ʹ�ÿͻ��˷������� httpResponse = httpClient。
      execute(httpGet); httpEntity = httpResponse。getEntity(); is = httpEntity。getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = ""; while((line = reader。
      readLine()) !=null){ result = result + line;} return result; } }。
      

    王***

    2014-06-18 16:27:26

类似问题

换一换
  • 手机使用 相关知识

  • 数码产品
  • 电子数码
  • 电子数码产品

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):