Home > Back-end >  RAD Server Delphi - using savetostream und loadfromstream does not work because of mutated vowels af
RAD Server Delphi - using savetostream und loadfromstream does not work because of mutated vowels af

Time:10-19

I try to exchange Data via RadServer IIS Package and Delphi Client with EMSEndpoint. What I try looks simple to me but I can't get it done now.

In the Package there is a TFDConnection pointing to a MSSql Server. TFDQuery is connected with that Connection. With this code I create the JSON Response (Serverside):

var lStream: TStringStream := TStringStream.create;

    FDQuery.SaveToStream(lStream,sfJSON);
    AResponse.Body.SetStream(lStream,'application/json' ,True);

with that code I try to load the Dataset into TFDMemtable (Clientside):

 lstrstream: TStringStream := TStringStream.create(EMSBackendEndpoint.Response.Content);
 aMemtable.LoadFromStream(lstrstream, sfJSON);

The Memtable says [FireDac][Stan]-719 invalid JSON storage format How could that be? I know where the Problem is, there are äöü Symbols in my Stream, but when I load that from one Component to the other it should work, shouldn't it? Any suggestions what I can try? What I have tryed so far:

  • Loading JSON in Client over UTF8toUnicode. That let me load the Memtable but results in missing Letters like öäü
  • Changing UTF8toUnicode on the Serverside and backwords on the Client side. That leads to not readable JSON for the Memtable
  • Loading JSON into JSONString and Format it localy before loading into Memtable. That leads to not Readable JSON because also the Array and Object chars are quoted out.

CodePudding user response:

JSON is most commonly exchanged using UTF-8, but by default TStringStream does not use UTF-8 on Windows, only on Posix systems. Try using TStringStream.Create(..., TEncoding.UTF8) to force UTF-8.

This assumes that FDQuery.SaveToStream() saves using UTF-8, and aMemtable.LoadFromStream() loads using UTF-8, otherwise you will still have an encoding mismatch.

  • Related