私は複数の行のtxtファイルに印刷したい辞書があります。複数行の文字列をブロブに印刷するには?
これを実現するために、私は:
1)JSON.stringifyを経由して文字列に辞書を変換(辞書)
2)ブロブに文字列を入力し、それを
私がいる手間を省きます出力は次のように、辞書の本当に醜い1行の結果であるということである。
{"key1":"value1","key2":"value2","key3":"value3",etc}
しかし、私はこのようにそれをしたい:
key1:value1
key2:value2
key3:value3
etc.
どうすればいいですか?
result = JSON.stringify(dict);
// Create blob instance and input the string
var blob1 = new Blob([result], { type: "text/plain" });
url = window.URL.createObjectURL(blob1);
// Create link to download the blob as txt file
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.setAttribute("download","My Open Tabs");
a.click();
window.URL.revokeObjectURL(url);
JSON.stringify => 'JSON.stringify(dict、null、 '');'の3番目の引数を使用します。ここを参照してくださいhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify – Fefux