当前位置: 代码迷 >> J2EE >> HttpURLConnection响应的JSON 数据部全是如何会事?
  详细解决方案

HttpURLConnection响应的JSON 数据部全是如何会事?

热度:27   发布时间:2016-04-22 01:09:00.0
HttpURLConnection响应的JSON 数据部全是怎么会事?在线等!!!!!
代码是这样的:
try{ 
String url= "http://m.qzone.qq.com/cgi-bin/new/msgb_output_page?uin=1234567&start=1&json=1&num=4"; 
URL login = new URL(url); 
HttpURLConnection conn =null; 

conn =(HttpURLConnection)login.openConnection();//openConnection();//打开链接 
HttpURLConnection.setFollowRedirects(true);
// conn.setRequestProperty( "username ", "username "); 
// conn.setRequestProperty( "password ", "userpwd ");

conn.setDoOutput(true);
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.setRequestMethod( "GET"); //
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String text ="";
while( null != br.readLine()){
text = text +br.readLine();
System.out.println(br.readLine());
}
}catch(Exception e){} 
用浏览器 返回的数据就是正常的、








------解决方案--------------------
String text2
while( (text2= br.readLine())!=null){
text = text +text2;

}
System.out.println(text);

实际上text一般是用stringbuffer或 stringbuilder的
  相关解决方案