如何将键值 class 转换为 json
how convert key value class to json
我是一个class,定义如下
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));
我是一个class,定义如下
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));