使用 TlkJSONobject 在 delphi xe3 中解析 JSON withi UTF-8 值

parse JSON withi UTF-8 Value in delphi xe3 with TlkJSONobject

我想解析 JSON 而不是 UTF-8 字符串,但是当我在标签中的 delphi XE3 中显示此值时,只显示 ????但是在 ShowMessage() 中显示时;这个值是正确的请帮助我 值:'سعید'

我的代码:

procedure TServerMethods1.Ins_Info(var TehResult: String);
var    
    name: string;
    js,xs:TlkJSONobject;
begin
    js := TlkJSON.ParseText(ThResult) as TlkJSONobject;
    if not assigned(js) then
    begin
        readln;
        exit;
   end
   else
   begin
      name := AnsiToUtf8(js.getString('name'));
   end;
end;

根据lkJSON单元的来源,有一个不必要的UTF8解码:

{$ifdef USE_D2009}
    js.FValue := UTF8ToString(ws);
{$else}
    js.FValue := UTF8Decode(ws);
{$endif}

如果您的 JSON 字符串未使用 UTF8 编码,请查找并注释这一行,然后将 ws 值分配给 js.FValue :

    ...

    js := TlkJSONstring.Create;

//{$ifdef USE_D2009}
//    js.FValue := UTF8ToString(ws);
//{$else}
//    js.FValue := UTF8Decode(ws);
//{$endif}

    js.FValue := ws;

    ...

并且不需要使用 AnsiToUtf8 或类似的方法,只需使用 getString :

name := js.getString('name');