私は使用しています スーパーオブジェクト JSONを操作するためのライブラリ。
このコードはJSONを作成します。
procedure TfmMain.btnIngredientsSaveClick(Sender: TObject);
var obj: ISuperObject;
i: integer;
begin
try
obj := SO();
for i := 0 to sgIngredients.RowCount - 2 do
begin
obj.O[sgIngredients.Cells[0, i+1]] := SA([]);
obj.A[sgIngredients.Cells[0, i+1]].S[0] := sgIngredients.Cells[1, i+1];
obj.A[sgIngredients.Cells[0, i+1]].S[1] := sgIngredients.Cells[2, i+1];
end;
obj.SaveTo(ExtractFileDir(Application.ExeName)+ingrJSONFile);
finally
obj := nil;
end;
end;
成分 - TStringGrid
sgコンポーネントにはキリル文字が含まれています。だから出力ファイルは次のとおりです。
{
"4":["Hello","count"],
"3":["u0411u0443u043bu044cu043eu043d u043eu0432u043eu0449u043du043eu0439","u0441u0442."],
"2":["u0411u0443u043bu044cu043eu043d u043au0443u0440u0438u043du044bu0439","u0441u0442."],
"1":["u0411u0435u043au043eu043d","u0433u0440."]
}
データを正しくJSONファイルに保存する方法は?
EDIT
これは私の文字列グリッドのスクリーンショットです。
回答:
回答№1の場合は3ソースを読んで、あなたは呼び出すことができます function TSuperObject.SaveTo(stream: TStream; indent, escape: boolean): integer;
設定 escape := false
与えられたソースコードでライブラリを使うとき、私は再びそれを言うことができます、ちょうど「Use the Source、Luke」
また、uはJSONを文字列に保存してから、エスケープされた文字を実際のWideChar値に置き換えます(たとえば、 http://UniRed.sf.net または http://www.sql.ru/forum/936760/perevesti-kodirovannye-simvoly-funkciya-v-delphi-analog-iz-jsその後、結果の文字列をファイルに保存し、utf-8文字セットを適用します。