我需要在 Datacontract 中返回一个结构数组。我做不到。设置数组的值时收到错误消息。
这是 Datacontract 声明:
[DataContract]
public class invoice_data
{
[DataMember]
public Invoice_Body_Item[] invoice_body;
}
[StructLayout(LayoutKind.Sequential)]
public struct Invoice_Body_Item
{
public string Item_Description;
public decimal Item_Value;
}
}
这是方法代码:
invoice_data Invoice = new invoice_data();
object tr_bl = svr.GetInvoiceData(inputparams.ck, svr.Confirm(inputparams.ck));
for (int i = ((Array)(((object[])(tr_bl))[1])).GetLowerBound(0); i <= ((Array)(((object[])(tr_bl))[1])).GetUpperBound(0); i++)
{
Invoice.invoice_body[i].Item_Description = (string)((object[])(((object[])(((object[])(tr_bl))[1]))[i]))[0];
Invoice.invoice_body[i].Item_Value = (decimal)((object[])(((object[])(((object[])(tr_bl))[1]))[i]))[1];
}
}
在这一行中,我收到错误“对象引用未设置为对象的实例”。
Invoice.invoice_body[i].Item_Description = (string)((object[])(((object[])(((object[])(tr_bl))[1]))[i]))[0];