我是一个定义如下的类
public class Param
{
public string Key { get; set; }
public object Value { get; set; }
public Param(string key, object value)
{
this.Key = key;
this.Value = value;
}
}
a具有值的对象
var params = new List<Param>(){new Param("k1","v1"),new Param("k2","v2"),new Param("k3","v3")};
如何使用这种结构构建json。
{
"k1":"v1",
"k2":"v2",
"k3":"v3"
}
var json = JsonSerializer.Serialize(params.ToDictionary(p => p.Key, p => p.Value));