Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

JObject out = JObject.FromObject(new
            {
                typ = "photos"
            });

            return out.ToString();

Output:

{
  "typ": "photos"
}

My question: Is it possible to get the output in a single line like:

{"typ": "photos"}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use the overload of JObject.ToString() which takes Formatting as parameter:

JObject obj = JObject.FromObject(new
{
    typ = "photos"
});

return obj.ToString(Formatting.None);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...