获取json返回数据,出了点问题,想请教下

mtngt11 2017-11-22 05:44:10
[size=18px][size=16px][size=14px][size=14px]想获取这个链接的返回数据
http://songsearch.kugou.com/song_search_v2?callback=jQuery191034642999175022426_1489023388639&keyword={歌曲名称}&page=1&pagesize=30&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_=1489023388641


正确返回的数据如下,后续太长了,贴出部分:
jQuery191034642999175022426_1489023388639({"status":1,"error_code":0,"data":{"page":1,"tab":"全部","lists":[{"SongName":"月亮代表我的心","OwnerCount":22906,"MvType":2,"TopicRemark":"","SQFailProcess":4,"Source":"","Bitrate":128,"HQExtName":"mp3","SQFileSize":19981329,"ResFileSize":87208855,"Duration":212,"MvTrac":3,"SQDuration":210,"ExtName":"mp3","Auxiliary":"歌词:我的情也真 我的爱也真 月亮代","SongLabel":"","Scid":342251,"FailProcess":4,"SQBitrate":762,"HQBitrate":320,"Audioid":342251,"HiFiQuality":4,"Grp":[{"SongName":"月亮代表我的心","OwnerCount":243,"MvType":2,"TopicRemark":"","SQFailProcess":4,"Source":"","Bitrate":128,"HQExtName":"mp3","SQFileSize":19981329,"ResFileSize":87208855,"Duration":212,"MvTrac":3,"SQDuration":210,"ExtName":"mp3","Auxiliary":"","SongLabel":"","Scid":342251,"FailProcess":4,"SQBitrate":762,"HQBitrate":320,"Audioid":342251,"HiFiQuality":4,"AlbumPrivilege":8,"TopicUrl":"","SuperFileHash":"9C228A6CF8418722B952FEEEBB3F5D72","ASQPrivilege":10,"M4aSize":876218,"AlbumName":"\"怀念.五年\"邓丽君逝世五周年纪念集","Privilege":8,"ResBitrate":3360,"HQFailProcess":4,"SQPayType":3,"HQPrice":200,"Type":"audio","SourceID":0,"FileName":"邓丽君 - 月亮代表我的


燃鹅我获取的是这样:
这就很尴尬了,,需要的lists下面的东西全没了。采用的代码如下
public String getData(String song) {      
StringBuffer strBuf;
String songUrl ="http://songsearch.kugou.com/song_search_v2?callback=jQuery19103464" +
"2999175022426_1489023388639&keyword={"+song+"}&page=1&pagesize=30&" +
"userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1" +
"&privilege_filter=0&_=1489023388641";
strBuf = new StringBuffer();
try {
String line = null;
URL url = new URL(songUrl);
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
// conn.setRequestMethod("GET");

//设置编码格式为UTF-8
conn.setRequestProperty("contentType", "UTF-8");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));//转码。

while ((line = reader.readLine()) != null)
strBuf.append(line + " ");
reader.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return strBuf.toString();
// Handler hander = new Handler();
}

我是抓取小白,请大神告诉我是哪儿出了问题呢,
[/size][/size][/size][/size]
...全文
163 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kampoo 2017-11-23
song一般需要URL编码,参考伪码

... + UrlEncoder.encode(song, "UTF-8") + ...// 如果没有结果,尝试GBK/UTF-16BE/UTF-16LE等多种编码。
如果服务器也是你写的,请在服务器上打印日志,看一下收到的'keyword'参数的值是什么。
  • 打赏
  • 举报
回复
mtngt11 2017-11-23
没有呀,我返回的json数据,里面的list{ }是空的,获取不到
  • 打赏
  • 举报
回复
李德胜1995 2017-11-22
有啊。。。。。。。。。。
  • 打赏
  • 举报
回复
相关推荐
发帖
Eclipse
加入

5.8w+

社区成员

Java Eclipse
申请成为版主
帖子事件
创建了帖子
2017-11-22 05:44
社区公告
暂无公告