gpt4 book ai didi

c# - C#中如何获取对象的值

转载 作者:太空狗 更新时间:2023-10-30 01:34:55 27 4
gpt4 key购买 nike

我的Json代码是

ListOrderDetails.push({ // Add Order Details to array                  
"OrderType": OrderType,
"CaseNumber": CaseNumber,
"OrderNumber": OrderNumber,
"OrderStatus": OrderStatus,
"Reason": Reason,
"Coments": Coments
});

var Params = { "Geo": Geography, "GeoId": GeographyID, "CountryCode": CountryCode, "Segment": Segment, "SubsegmentID": SubSegmentID, "OrderDetails": ListOrderDetails };
//var Params = { "Geo": Geography, "GeoId": GeographyID, "CountryCode": CountryCode, "Segment": Segment, "SubsegmentID": SubSegmentID };
$.ajax({
type: "POST",
url: "MyDataVer1.aspx/SaveManualEntry",
contentType: "application/json",
data: JSON.stringify(Params),
dataType: "json",
success: function(response) {
alert(response);
},
error: function(xhr, textStatus, errorThrown) {
alert("xhr : " + xhr);
alert("textStatus : " + textStatus);
alert("errorThrown " + errorThrown);
}
});

c# web 方法是

[WebMethod]
public static int SaveManualEntry(string Geo, int GeoId, string CountryCode,
string Segment, string SubsegmentID,
object[] OrderDetails)
{

try
{
int TotalOrderCount = 0;
int Successcount = 0;
return Successcount;

}
catch (Exception ex)
{
throw ex;
}

}

如何从对象 orderDetails 获取值。我不能使用索引。

最佳答案

你可以使用反射:

foreach(var order in orderDetails)
{
string orderType = (string)order.GetType().GetProperty("OrderType").GetValue(order);
// other properties
}

关于c# - C#中如何获取对象的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28339876/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com