我在我的HTML代碼中收集了一些工單,從中收集JQuery信息併成功發佈到JSON中,以便通過AJAX進行代碼隱藏。將C#中的JSON反序列化爲元組的LinkedList
這裏是JSON文件:
{
'arrayTickets':
[
{"num":1,"rec":"SWAFAD","temp":"0","id":"f39443aa-1ae1-4d18-82b8-468f14dac507"},
{"num":1,"rec":"admin","temp":"0","id":"20bf1fea-b03e-4a28-922a-9618c8c8a73f"} ]
}
的問題是,我似乎無法能夠將其反序列化到我想要的結構類型:
[WebMethod]
public static void cmd_gravar_Click(string arrayTickets)
{
JavaScriptSerializer json = new JavaScriptSerializer();
LinkedList<Tuple<int, string, string, string>> tickets = json.Deserialize<LinkedList<Tuple<int, string, string, string>>>(arrayTickets);
}
我得到的錯誤:
No parameterless constructor defined for type of 'System.Tuple`4[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
我想繼續使用這個結構,因爲我已經創建了一個工作方法來保存da ta與它的數據庫。這是通過webforms完成的。
編輯:使用VS2012
感謝。無法安裝包,因爲我在VS2012,顯然我需要NuGet 2.12+這是不可用。 –
等等,結果我不需要安裝它,我可以運行代碼。問題是變量「結果」具有正確數量的項目,但int值全部爲0,字符串全爲空。 –