How can I beautify JSON for display in a TextBox?

后端 未结 3 542
北海茫月
北海茫月 2020-12-29 01:06

How can I beautify JSON with C#? I want to print the result in a TextBox control.

Is it possible to use JavaScriptSerializer for this, or should I use JSON.net? Un

3条回答
  •  梦谈多话
    2020-12-29 01:48

    Bit late to this party, but you can beautify (or minify) Json without deserialization using json.NET:

    JToken parsedJson = JToken.Parse(jsonString);
    var beautified = parsedJson.ToString(Formatting.Indented);
    var minified = parsedJson.ToString(Formatting.None);
    

提交回复
热议问题