一、酷狗 歌词搜索 Indy TIdhttp
酷狗歌词Url: http://lib9.service.kugou.com/websearch/index.php?page=1&cmd=100&pagesize=9&keyword= +歌名
酷狗歌词编码:UTF-8
中文歌名转UTF8编码代码
1 function StrToHex(str: string; AEncoding: TEncoding): string; 2 var 3 ss: TStringStream; 4 i: Integer; 5 begin 6 Result := ‘‘; 7 ss := TStringStream.Create(str, AEncoding); 8 try 9 for i := 0 to ss.Size - 1 do 10 Result := Result + ‘%‘ + Format(‘%.2x‘, [ss.Bytes[i]]); 11 finally 12 ss.Free; 13 end; 14 end;
StrToHex(歌词,TEncoding.utf8)
TIdhttp调用代码
1 function httpGetByStream(Url:string;AEncoding:TEncoding):TStringStream; 2 begin 3 try 4 Result := TStringStream.Create(‘‘, AEncoding); 5 FIdhttp := TIdHTTP.Create(nil); 6 FIdhttp.ConnectTimeout := 3000; 7 FIdhttp.ReadTimeout := 6000; 8 FIdhttp.Get(FUrl, Result); 9 finally 10 FIdhttp.Disconnect; 11 FreeAndNil(FIdhttp); 12 end; 13 end; 14 15 var 16 ReStreamBuff : TStringStream; 17 begin 18 //以Utf8编码格式实例化字符串流, 19 ReStreamBuff := TStringStream.Create(‘‘, TEncoding.UTF8); 20 try 21 ReStreamBuff := httpGetByStream(FUrl, TEncoding.UTF8); 22 //do datasting; 23 finally 24 ReStreamBuff.Free; 25 end; 26 end;
最后解析出来的ReStreamBuff为字符串流,其Datastring为JSON串
使用系统自带的System.JSON类解析即可
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。