C#快速生成json字符串

单个json

var requestData = request.JsonSerializer.Serialize(new
{
   name = "11",
   age = "22"
});

生成的json字符串
{
“name”: “11”,
"age ": “22”
}

json里包含json

var requestData = request.JsonSerializer.Serialize(new
{
    name = "11",
    age = "22",
    school = new
    {
        className = "二班"
    }
});

生成的json字符串
{
“name”: “11”,
"age ": “22”,
"school ": "{"className ": “二班”}
}

你可能感兴趣的:(c#)