首页 > Web开发 > 详细

一、酷狗 歌词搜索 Indy TIdhttp

时间:2014-11-10 19:34:51      阅读:367      评论:0      收藏:0      [点我收藏+]

酷狗歌词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类解析即可

 

一、酷狗 歌词搜索 Indy TIdhttp

原文:http://www.cnblogs.com/ab0416/p/4087626.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!