zoukankan      html  css  js  c++  java
  • Delphi解析类似\u97e9这样的Unicode字符串

    使用Delphi对Json中的Unicode字符串进行解析:
    [{"name":"\u97e9\u56fd\u9996\u5c14KT\u670d\u52a1\u5668","ip":"211.115.67.40"},{"name":"\u97e9\u56fd\u5357\u90e8","ip":"211.115.67.40"}]
     
    function TForm1.DecodeUnicodeString(const S: string): string;
    var
      buf: array[0..4] of Char;
      i: Integer;
      Ch, PvCh: Char;
      US: string;
      Str: string;
    begin
      Result := '';
      ZeroMemory(@buf[0], SizeOf(buf));
      i := 1;
      while i < Length(S) do
      begin
        Ch := S[i];
        if (Ch = 'u') and (i > 1) then
        begin
          PvCh := S[i-1];
          if PvCh = '\' then
          begin
            US := Copy(S, i+3, 2) + Copy(S, i+1, 2);
            HexToBin(PChar(US), buf, 2);
            Str := WideCharToString(@buf[0]);
            Result := Copy(Result, 1, Length(Result)-1);  // drop "\"
            Result := Result + Str;
            Inc(i, 5);
            Continue;
          end;
        end;
        Inc(i, 1);
        Result := Result + Ch;
      end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      ShowMessage(DecodeUnicodeString('\u97e9\u56fd\u9996\u5c14KT\u670d\u52a1\u5668'));
    end;

    运行结果

  • 相关阅读:
    python-django学习
    c++异常处理
    Python输入输出
    Python变量
    Python异常处理
    Python起源与发展
    vsftpd基于mysql的认证方式
    vsftpd搭建ftp服务,并实现虚拟用户访问
    httpd结合php的fpm模式
    编译安装apache
  • 原文地址:https://www.cnblogs.com/ddgg/p/2952866.html
Copyright © 2011-2022 走看看