关于获取WEB内容后的字符转换(200)

  • 主题发起人 主题发起人 Magic
  • 开始时间 开始时间
M

Magic

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是获取的WEB内容:{"error":true,"result":"/u60a8/u5c1a/u672a/u767b/u5f55/u6216/u8005/u767b/u5f55/u4fe1/u606f/u5df2/u7ecf/u8d85/u65f6/uff0c/u8bf7/u91cd/u65b0/u767b/u5f55/uff01","script_code":"window.location = '//';","script_text":null,"confirm":false,"self":false}请问怎么转换以上的result对应的字符?哪位做过,帮忙出个主意。
 
function WSCodeToString(const AWSCode: string): string;const ERR_STR = '###########';var iPos: Integer; mstr, substr, mv: WideString;begin Result := ''; mstr := AWSCode; iPos := Pos('/u', mstr); while iPos>0 do begin substr := Copy(mstr, iPos+2, 4); try mv := WideChar(StrToInt('$' + substr)); mstr := StringReplace(mstr, '/u'+substr, mv, [rfReplaceAll]); except mstr := StringReplace(mstr, '/u'+substr, ERR_STR+substr, [rfReplaceAll]); end; iPos := Pos('/u', mstr); end; Result := StringReplace(mstr, ERR_STR, '/u', [rfReplaceAll]);end;/u60a8/u5c1a/u672a/u767b/u5f55/u6216/u8005/u767b/u5f55/u4fe1/u606f/u5df2/u7ecf/u8d85/u65f6/uff0c/u8bf7/u91cd/u65b0/u767b/u5f55/uff01您尚未登录或者登录信息已经超时,请重新登录!
 
能不能在GET到WEB内容时自动进行转换呢?
 
这个格式是 Json 的.网上有 Delphi 的 Json 解析单元。以下是一个解析的例子。program sample;{$APPTYPE CONSOLE}uses SysUtils,Classes,uLkJSON;procedure JsonText(TmpBase:TlkJSONbase;Const sTitle:String='');var i:Integer; TmpStr,sRoot:String;begin case TmpBase.SelfType of jsList: begin for i:=1 to TmpBase.Count do begin sRoot:=ConCat(sTitle,IntToStr(i),'/'); JsonText(TmpBase.Child[i-1],sRoot); end; end; jsBase,jsObject: begin for i:=1 to TmpBase.Count do begin sRoot:=ConCat(sTitle,TlkJsonObject(TmpBase).NameOf[i-1],'/'); JsonText(TlkJsonObject(TmpBase).FieldByIndex[i-1],sRoot); writeln end; end; jsNumber, jsString, jsBoolean, jsNull: begin TmpStr := TlkJSON.GenerateText(TmpBase); writeln(ConCat('Field:',sTitle)); writeln(ConCat('Value:',TmpStr)); end; end;end;function JsonBase(sTitle:String;TmpBase:TlkJSONbase):TlkJSONbase;var i,l:Integer; TmpStr:String; TmpList:TStringList;begin try TmpList:=TStringList.Create; TmpList.Delimiter:='/'; TmpList.DelimitedText:=sTitle; for i:=1 to TmpList.Count do begin TmpStr:=TmpList.Strings[i-1]; l:=StrToIntDef(TmpStr,-1); if Assigned(TmpBase) then begin if (TmpBase.SelfType=jsList)and(l>=0) then TmpBase:=TmpBase.Child[l-1] else TmpBase:=TmpBase.Field[TmpStr]; end else Break; end; Result:=TmpBase; finally freeandnil(TmpList); end;end;var SourceBase, TmpBase:TlkJSONbase;begin try SourceBase := TlkJSON.ParseText('{"cacheControl":{"seed":11,"tool":1,"diy":3},"a":false,"b":1259926521,"c":false,"task":{"taskId":0,"taskFlag":0}}'); JsonText(SourceBase); writeln('---------------Over-----------------'); readln; finally freeandnil(SourceBase); end;end.
 
感谢,让我对Json有个初步认识。
 
多人接受答案了。
 
后退
顶部