I have an issue with the JSON string I get when receiving a POST request. Currently this is the way I'm reading it:
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  Stream : TStream;
  S : string;
begin
  If ARequestInfo.Command = 'POST' then
  begin
    Stream := ARequestInfo.PostStream;
    if assigned(Stream) then
    begin
      Stream.Position := 0;
      S := UTF8ToAnsi(ReadStringFromStream(Stream));
    end;
  end;
end;
I tried ReadStringFromStream() alone and with UTF8ToAnsi()and AnsiToUTF8(), but I keep getting a string that looks like this:
'['#$A#9'{'#$A#9#9'"test":"bb",'#$A#9#9'"test":"aa"'#$A#9'}'#$A']'
I know it has something to do with encoding, but I don't know how to fix it.
You do know that the hash (#) sign denotes a character value and that the dollar ($) sign denotes hexadecimal values, do you. Thus #$A means character decimal 10, which happens to mean NewLine and #9 means character 9 which is the TAB character. There is nothing unexpected in the return string. If you feed it into something that understands a NewLine without a preceding CarriageReturn it will probably look as you expected.
The debugger for exmple, uses the #-syntax for characters that cant be otherwise visually represented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With