Generate JSON object with NewtonSoft in a single line

后端 未结 5 2042
自闭症患者
自闭症患者 2020-12-04 20:49

I\'m using the JSON library NewtonSoft to generate a JSON string:

JObject out = JObject.FromObject(new
            {
                typ = \"photos\"
                


        
5条回答
  •  無奈伤痛
    2020-12-04 21:32

    Here's a one-liner to minify JSON that you only have a string for:

    var myJson = "{\"type\"    :\"photos\"               }";
    JObject.Parse(myJson).ToString(Newtonsoft.Json.Formatting.None)
    

    Output:

    {"type":"photos"}
    

提交回复
热议问题