zoukankan      html  css  js  c++  java
  • 一、酷狗 歌词搜索 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类解析即可

  • 相关阅读:
    The first appliaction for "Hello World!"
    zone
    learn to study
    深入理解 Angular 2 变化监测和 ngZone
    看看吧
    生命周期钩子
    一个简单的todo
    依赖注入
    @Output()
    @Input
  • 原文地址:https://www.cnblogs.com/ab0416/p/4087626.html
Copyright © 2011-2022 走看看