Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

System.Json output UTF8 escaped String

$
0
0

I am trying to build JSON objects that contain UNICODE characters but using the .ToJson property it just escapes all unicode characters and does not create it as UTF-8. Using the ToString property it creates it as UTF-8 but does not escape the required characters and generates un-parsable JSON.

Considering:

var
  LJson : TJSONObject;
begin
    LJson := TJSONObject.Create;
    try
        LJson.AddPair('Время', 'Время');
        LJson.AddPair('Some\Thing', 'Some/Thing');
        LJson.AddPair('世界新聞網', '世界新聞網');

        Memo1.Text := TJSONArray(LJson).ToJSON;
        Memo2.Text := TJSONArray(LJson).ToString;
    finally
        LJson.Free;
    end;

Memo1 = 

{
  "\u0412\u0440\u0435\u043C\u044F": "\u0412\u0440\u0435\u043C\u044F",
  "Some\\Thing": "Some\/Thing",
  "\u4E16\u754C\u65B0\u805E\u7DB2": "\u4E16\u754C\u65B0\u805E\u7DB2"
}

Memo2 = 

  {
    "Время": "Время",
    "Some\Thing": "Some/Thing",
    "世界新聞網": "世界新聞網"
  }

But what I need to output is:

  {
    "Время": "Время",
    "Some\\Thing": "Some\/Thing",
    "世界新聞網": "世界新聞網"
  }

 

 


Viewing all articles
Browse latest Browse all 3212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>