当在对象中填充值时,当我序列化OverallMainUserActivity对象时,我无法获得所需的确切格式。是否有可能从C#中的对象序列化中获得这种结果?如何在C#中序列化这个特定的json格式
预期的格式:
{
"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
}
有一种使用阵列来获得预期的格式以特殊的方式?
如果您正在使用visual studio - 编辑菜单中有“PASTE SPECIAL”选项。将JSON复制到内存中,当您单击“粘贴JSON”时,这将为您创建类。 – Programmer
为什么不把内部分数放在内部数组中而不是对象? – Bindrid
我不了解@Bindrid的建议和第一条评论告诉我一个很好的功能,在VS我没有注意多年。 –