JSON の文字列を入力として受け取り、改行とインデント (タブ) でフォーマットする関数を探しています。
例: 入力行があります:
{"menu": {"header": "JSON viewer", "items": [{"id": "Delphi"},{"id": "Pascal", "label": "Nice tree format"}, null]}}
そして、読みやすい結果をテキストとして取得したい:
{
"menu":{
"header":"JSON viewer",
"items":[
{
"id":"Delphi"
},
{
"id":"Pascal",
"label":"Nice tree format"
},
null
]
}
}
PHP と C# の例はたくさん見つかりましたが、Delphi の例は見つかりませんでした。誰かがそのような機能を手伝ってもらえますか?
更新 - SuperObject を使用したソリューション:
function FormatJson (InString: WideString): string; // Input string is "InString"
var
Json : ISuperObject;
begin
Json := TSuperObject.ParseString(PWideChar(InString), True);
Result := Json.AsJson(true, false); //Here comes your result: pretty-print JSON
end;