1

I have a Delphi XE2 Datasnap server and I need to receive a string with line breaks from a database and resend it as a JSON String to the client application. The problem is I'm receiving the string with #10#13 line breaks, and my client expects \n linebreaks. That seems to be the JSON default way of sending line breaks and I was expecting the conversion to be automatic, but seemingly it isn't so.

I'm thinking of implementing a method for conversion of my own, but that would be in a worst-case scenario, and I want to avoid a possible "reinvent the wheel" scenario. So my question is, is there a better option?

4

1 に答える 1

3

#10 は改行またはライン フィード (LF) 文字であり\n、c 派生言語で#13は として表され、キャリッジ リターン (CR) は として表され\rます。Windows および一部のインターネット プロトコル (SMTP や HTTP など) での通常の順序は です\r\n

残念ながら、異なるオペレーティング システムでは異なる改行が使用されます ( http://en.wikipedia.org/wiki/Newlineも参照) 。

Delphi (または使用する JSON フレームワーク) は、改行の期待値を推測できません。残念ながら、改行をクライアントに合わせて追加のコードを作成する必要があります。

実際には、文字列がデータベースまたはその他のソースから取得され、リテラル CR LF シーケンスで格納されている可能性があります。Delphi はそれらを変更せずに渡しているだけです。

仕事をする前に、クライアントが本当に気にかけていることを確認してください。

于 2012-06-14T04:07:45.337 に答える