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連接 然后決議歌詞 求大神
uj5u.com熱心網友回復:
拿走不謝
Matcher matcher = Pattern.compile("(?<=\"lrc\":\").+?\\.lrc").matcher(jsonString);
while (matcher.find()){
System.out.println(matcher.group());
}
或者用fastjson直接轉物件,也挺方便,還能獲取其他資訊,自己搜fastjson教程
uj5u.com熱心網友回復:
或者用fastjson直接轉物件,也挺方便,還能獲取其他資訊,自己搜fastjson教程uj5u.com熱心網友回復:
誤人子弟啊
uj5u.com熱心網友回復:
決議json,就能拿到uj5u.com熱心網友回復:
2潭訓復合并一塊可以了吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/32239.html
標籤:Android
下一篇:遇到java.lang.SecurityException: Not allowed to start activity Intent的問題
