How do I save a JSON file with four spaces indentation using JSON.NET?

后端 未结 3 1367
无人共我
无人共我 2020-12-15 22:59

I need to read a JSON configuration file, modify a value and then save the modified JSON back to the file again. The JSON is as simple as it gets:

{
    "         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 23:46

    Maybe try to feed a tab character to the IndentChar?

    ...    
    jw.IndentChar = '\t';
    ...
    

    Accordinging to the documentation, it should use the tab character to indent the JSON instead of the space character. http://james.newtonking.com/json/help/index.html?topic=html/T_Newtonsoft_Json_Formatting.htm

提交回复
热议问题