因为字符编码的问题,害我折腾了两个小时。以下是代码,大家看一下就明白了。 String url = "https://www.google.com/ig/api?weather=,,,31174165,121433841"; DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest req = new HttpGet(url); HttpResponse resp = client.execute(req); HttpEntity ent = resp.getEntity(); int status = resp.getStatusLine().getStatusCode(); if(L.Debug) { L.d("" + status); } // 若状态码为 200 ,则表示OK if (status == HttpStatus.SC_OK) { //String result = EntityUtils.toString(ent); if(L.Debug) { //L.d(result); } InputStream stream = ent.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(stream, "utf-8")); DocumentBuilder b = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); String xmlString = ""; for(String temp = br.readLine(); temp != null;xmlString += temp ,temp = br.readLine()); // 去除字符串中的换行符,制表符,回车符。 xmlString = xmlString.replaceAll("/n|/t|/r", ""); InputStream stream2 = new ByteArrayInputStream(xmlString.getBytes()); Document d = b.parse(new InputSource(stream2)); NodeList n = d.getElementsByTagName("forecast_conditions"); String tips = ""; tips += n.item(0).getChildNodes().item(0).getAttributes() .item(0).getNodeValue(); if(L.Debug) { L.d("" + tips ); L.d("" + n.item(0).getChildNodes().getLength()); //L.Toast(tips, this); } br.close(); stream.close(); stream2.close(); }Stri 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交