當在對象中填充值時,當我序列化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我沒有注意多年。 –