C# json拼接

环境搭建

在Nuget 添加:Newtonsoft.Json

拼Json

单个

            JObject jo = new JObject();
            jo["Name"] = "张三";
            jo["Code"] = "1";
            string str = JsonConvert.SerializeObject(jo); 
//结果
{
"Name":"张三",
"Code":"1"
}

数组形式

            JObject jo = new JObject();
            jo["Name"] = "张三";
            jo["Code"] = "1";
            JArray jarray = new JArray();
            jarray.Add(jo);
            string str = JsonConvert.SerializeObject(jarray);
//结果
[{
"Name":"张三",
"Code":"1"
}]
posted @ 2020-04-15 14:44  Alex_Mercer  阅读(533)  评论(0编辑  收藏  举报