本文整理自网络,侵删。
</pre><pre code_snippet_id="76206" snippet_file_name="blog_20131121_2_2675795" name="code" class="javascript">{"result":["{\"ServerCount\":2,\"Servers\":[{\"ServerName\":\"\u672C\u573014\u670D\",\"ServerIP\":\"172.16.228.14:8000\"},{\"ServerName\":\"\u7535\u4FE1\u6D4B\u8BD5\u670D\",\"ServerIP\":\"12.23.34.45:8000\"}]}\r\n"]}
转换后效果
{"result":["{"servercount":2,"servers":[{"servername":"本地14服","serverip":"172.16.228.14:8000"},{"servername":"电信测试服","serverip":"12.23.34.45:8000"}]}"]}
function wwChangeUTF8ToWideString(szJson :string):string; function XDigit(Ch : AnsiChar) : Integer; begin if (Ch >= '0') and (Ch <= '9') then Result := Ord(Ch) - Ord('0') else Result := (Ord(Ch) and 15) + 9; end; function wwUtfToString(szUtf: string):string; var I:Integer; Index:Integer; WChar:WideChar; WCharWord:Word; AChar:AnsiChar; begin WCharWord:=0; for i := 1 to Length(szUtf) do begin AChar := AnsiChar(szUtf[i]); WCharWord := WCharWord + XDigit(AChar) * Ceil(Power(16,4-i)); end; WChar := WideChar(WCharWord); Result := WChar; end;var Index:Integer; HexStr:String;begin szJson := LowerCase(szJson); szJson := StringReplace(szJson, '\"', '"', [rfReplaceAll]); szJson := StringReplace(szJson, '\r', #10, [rfReplaceAll]); szJson := StringReplace(szJson, '\n', #13, [rfReplaceAll]); szJson := StringReplace(szJson, '\\', '\', [rfReplaceAll]); Index := PosEx('\u',szJson,1); while Index>0 do begin HexStr:=Copy(szJson,Index+2,4); wwUtfToString(HexStr); szJson := StringReplace(szJson, '\u'+HexStr, wwUtfToString(HexStr),[rfReplaceAll]); Index:=PosEx('\u',szJson,1); end; Result := szJson; // byWarrially end;
――――――――――――――――
原文链接:https://blog.csdn.net/warrially/article/details/16862853
相关阅读 >>
[Delphi] 计算目录大小的函数,获得目录文件列表,计算文件的大小
Delphi 工程判断内存溢出reportmemoryleaksonshutdown := true;
Delphi xe 10.2.1 fmx平台 在图片上写字方法
Delphi中转向语句break,continue,exit的作用
更多相关阅读请进入《Delphi》频道 >>