[英]How to serialize this specific json format in C#
在对象中填充值时,当我序列化TotalMainUserActivity对象时,我无法获得所需的确切格式。 C#中对象的序列化是否可能产生这种结果?
预期格式:
{
"Registration": [
{
"1": "10",
"2": "2",
"3": "20",
"4": "20",
"5": "20",
"6": "20",
"7": "20",
"8": "20",
"9": "20",
"10": "20"
}],
"Withdrawal": [
{
"1": "10",
"2": "2",
"3": "20",
"4": "20",
"5": "20",
"6": "20",
"7": "20",
"8": "20",
"9": "20",
"10": "20"
}]
}
我努力了
public class OverallUserMainActivity
{
#region Not_suitable
public List<KeyValuePair<string, string>> Registration = new KeyValuePair<string, string>();
public List<KeyValuePair<string, string>> Withdrawal = new KeyValuePair<string, string>();
#endregion
#region Not_suitable
public Dictionary<string, string> Registration = new Dictionary<string, string>();
public Dictionary<string, string> Withdrawal = new Dictionary<string, string>();
#endregion
#region Not_suitable
public List<RegistrationCls> Registration = new List<Dictionary<string, string>>();
public List<WithdrawalCls> Withdrawal = new List<Dictionary<string, string>>();
#endregion
}
有使用数组获取所需格式的特殊方法吗?
使用List<Dictionary<string, string>>
应该可以工作
我只是做了最起码的演示,以证明它能正常工作,在您的情况下,您可能会有一些嵌套循环或LINQ查询,以将您的数据转换为List
项和Dictionary
项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.