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"
}]