网易API
对于网易的API,主要有如下一些参数:
参数 | 取值 |
---|---|
src | lofter,可为空 |
type | 1:单曲 10:专辑 100:歌手 1000:歌单 1002:用户 |
s | 查询的关键字 |
limit | 返回的结果条数 |
offset | 偏移 |
callback | 回调,为空则返回json,否则为jsonp |
比如搜索ヒトリゴト
http://s.music.163.com/search/get/?type=1&limit=3&s=ヒトリゴト
则返回以下Json:
{"result": {"songCount":384,"songs": [
{"id":473964449,
"name":"ヒトリゴト",
"artists":[{"id":18961,"name":"ClariS","picUrl":null}],
"album":{"id":35425186,"name":"ヒトリゴト (アニメ盤)","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/XimGbGkuMKgWie-MFhyVsQ==/18633423557795030.jpg"},
"audio":"http://m2.music.126.net/BEX6J9vA0U3erb677wlYww==/18819241022922967.mp3",
"djProgramId":0,"page":"http://music.163.com/m/song/473964449"},
{"id":522987,
"name":"ヒトリゴト",
"artists":[{"id":15558,"name":"玉置浩二","picUrl":null}],
"album":{"id":49224,"name":"PRESENT","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/QTNqgvdOYT2zCpOTN0xIOg==/807041534787864.jpg"},
"audio":"http://m2.music.126.net/hPeTtdFdDbGj7zs4jzGlgA==/2015404813718539.mp3",
"djProgramId":0,"page":"http://music.163.com/m/song/522987"},
{"id":22694321,
"name":"ヒトリゴト",
"artists":[{"id":18179,"name":"yozuca*","picUrl":null}],
"album":{"id":2082222,"name":"yozuca10周年ベストアルバム Vol.2 バラード盘","artist":{"id":0,"name":"","picUrl":null},"picUrl":"http://p1.music.126.net/Ug28y9KUzypzgeOATcB-PQ==/748767418537435.jpg"},
"audio":"http://m2.music.126.net/Jlp2mcq_5NgzZ_6CRXYZOQ==/1291926162640656.mp3",
"djProgramId":0,"page":"http://music.163.com/m/song/22694321"}]},
"code":200}```
下面给出该Json的处理函数(limit大于1时取第一首URL,JAVA或安卓可以用)
public static String parserMusicJson(String json){
String url="";
if(json!=null){
try {
JSONTokener token=new JSONTokener(json);
JSONObject jsonObject=new JSONObject(token);
JSONObject result=jsonObject.getJSONObject("result");
JSONArray songs=result.getJSONArray("songs");
JSONObject song0=songs.getJSONObject(0);
url=song0.getString("audio");
} catch (Exception e) {
e.printStackTrace();
}
}
return url;
}
c#版(使用前导入Newtonsoft.Json需要自行下载,可以获取url,作者,封面url,歌名)
public void jsonParser(string jsonText)
{
try
{
JObject o = (JObject)JsonConvert.DeserializeObject(jsonText);
JObject result = (JObject)o["result"];
JArray songs = (JArray)result["songs"];
string audio = (string)songs[0]["audio"];
string name = (string)songs[0]["name"];
JArray artists = (JArray)songs[0]["artists"];
string aname = (string)artists[0]["name"];
JObject album = (JObject)songs[0]["album"];
string picUrl = (string)album["picUrl"];
label1.Text = "正在播放:" + aname + " - " + name;
pictureBox1.ImageLocation = picUrl;
axWindowsMediaPlayer1.URL = audio;
}
catch (Exception e)
{
}
}