android关于json数组提取lrc地址

小ZC 2020-05-23 10:11:17
public String get(String url) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url(url)
.method("GET", null)
.build();
Response response = client.newCall(request).execute();

return response.body().string();
}
//歌词
public void getLyricFromGet() {
new Thread() {
@Override
public void run() {
super.run();
try {
String Str=songList.get(i).getSong();
String[] string=Str.split("[.]") ;
// curl 'http://gecimi.com/api/lyric/海阔天空/Beyond'
String url = "http://geci.me/api/lyric/" + string[0].trim();
System.out.println(url);
String result = get(url);
Log.e("TAG", result);
Message msg = Message.obtain();
msg.what = GET;
msg.obj = result;
handler.sendMessage(msg);



} catch (IOException e) {
e.printStackTrace();
}
}
}.start();

}
获取到了json数组
2020-05-23 22:10:19.887 11397-11453/com.example.administrator.mdsd E/TAG: {"code":0,"count":7,"result":[{"aid":2418554,"artist_id":2,"lrc":"http://s.gecimi.com/lrc/284/28457/2845727.lrc","sid":2845727,"song":"囚鸟"},{"aid":1742006,"artist_id":13177,"lrc":"http://s.gecimi.com/lrc/190/19071/1907111.lrc","sid":1907111,"song":"囚鸟"},{"aid":1982846,"artist_id":13177,"lrc":"http://s.gecimi.com/lrc/223/22360/2236028.lrc","sid":2236028,"song":"囚鸟"},{"aid":1860329,"artist_id":15843,"lrc":"http://s.gecimi.com/lrc/206/20670/2067030.lrc","sid":2067030,"song":"囚鸟"},{"aid":2635202,"artist_id":15843,"lrc":"http://s.gecimi.com/lrc/315/31502/3150238.lrc","sid":3150238,"song":"囚鸟"},{"aid":2671022,"artist_id":42486,"lrc":"http://s.gecimi.com/lrc/319/31992/3199273.lrc","
怎样提取出里面的LRC连接 然后解析歌词 求大神
...全文
174 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
王能 2020-05-27
  • 打赏
  • 举报
回复
引用 3 楼 yung7086 的回复:
[quote=引用 1 楼 王能 的回复:] 拿走不谢

        Matcher matcher = Pattern.compile("(?<=\"lrc\":\").+?\\.lrc").matcher(jsonString);
        while (matcher.find()){
            System.out.println(matcher.group());
        }
误人子弟啊[/quote] 2条回复合并一块可以了吧
qq_31699831 2020-05-26
  • 打赏
  • 举报
回复
解析json,就能拿到
yung7086 2020-05-26
  • 打赏
  • 举报
回复
引用 1 楼 王能 的回复:
拿走不谢

Matcher matcher = Pattern.compile("(?<=\"lrc\":\").+?\\.lrc").matcher(jsonString);
while (matcher.find()){
System.out.println(matcher.group());
}


误人子弟啊
王能 2020-05-24
  • 打赏
  • 举报
回复
或者用fastjson直接转对象,也挺方便,还能获取其他信息,自己搜fastjson教程
王能 2020-05-24
  • 打赏
  • 举报
回复
拿走不谢

Matcher matcher = Pattern.compile("(?<=\"lrc\":\").+?\\.lrc").matcher(jsonString);
while (matcher.find()){
System.out.println(matcher.group());
}


或者用fastjson直接转对象,也挺方便,还能获取其他信息,自己搜fastjson教程

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧