我创建了一个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'类是什么? –