本文介紹了使用 Json.net 編寫 JSON 時(shí)如何打開縮進(jìn)?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在使用 Json.Net 將 XML 序列化為 Json .當(dāng)我將序列化的字符串寫入文件時(shí),它都在一行中.我如何讓它看起來像 Json 并帶有通常的制表符和縮進(jìn)?
I am using Json.Net to serialize XML into Json . When i write the serialized string to a file it all comes in a single line . How do i get it to actually look like Json with the usual tabs and indentation?
推薦答案
設(shè)置 JSON 編寫器 Formatting
屬性到 Formatting.Indented
:
Set the JSON writer Formatting
property to Formatting.Indented
:
jsonWriter.Formatting = Formatting.Indented;
JsonConvert.Serialize*
方法還具有采用 Formatting
枚舉的重載(感謝 John Flatness).
The JsonConvert.Serialize*
methods also have overloads that take a Formatting
enum (thanks John Flatness).
文檔:序列化對象
這篇關(guān)于使用 Json.net 編寫 JSON 時(shí)如何打開縮進(jìn)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!