我創建了一個retreives JSON和分析它的通用功能:將IList <Object>投射到IList <CustomObject>?
public IList<Object> RetrieveView(string result)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
IList<Object> values = ser.Deserialize< IList<Object> >(result);
return values;
}
,我有很多使用這個類的問題。 例如,當我嘗試使用此:
IList<Receipt> receipts = (IList<Receipt>)RetrieveView(result);
我得到InvalidCastException
Unable to cast object of type 'System.Collections.Generic.List[System.Object]' to type 'System.Collections.Generic.IList[Receipt]'.
反正讓我的通用功能,並能夠將其轉換爲我所有的類/型號的?
你的JSON的外觀和你的'Reciept'類是什麼? –