Delphi Function to Parse JSON Unicode Chars

Posted on September 12, 2020 at 11:52 am

You can correctly parse/convert these JSON unicode characters:

\u3048\u305F\u5834\u5408\u3001\u305D\u306E\u307E\u307E\u30B7\u30EA\u30A2\u30E9\u30A4\u30BA\u3059\u308B\u3068

Into their real UTF-8 characters like:

えた場合、そのままシリアライズすると
procedure DecodeJsonUnicodeBytes(const sJson: String): String;
var
  LJSONObject: TJSONObject;
begin
  LJSONObject := nil;
  try
    LJSONObject := TJsonObject.Create;
    { convert String to JSON }
    LJSONObject.Parse(BytesOf(sJson), 0);
 
    { get the JSON as String }
    result := LJSONObject.ToString;
  finally
    LJSONObject.Free;
  end;
end;

Reference:

http://shankarjdelphi.blogspot.com/2019/03/delphi-json-parsing.html

Receive updates via email

Other Posts

Updated Posts