我有一个带有 3 个选项下拉菜单的贝宝购物车按钮。第一个是 Style - Tee, Sweat, Hood - 这个每个都有一个价格,然后还有另外两个 Size 和 Color。这是一个 C# ASP.NET 应用程序。如果我查看侦听器获得的整个响应(所有变量),则样式为“option_name1_1”,它应返回“样式”。但是在列表'option_selection_1_1'=“Sweat”中,这是我选择的,但是当我调用该值时它没有显示任何内容。这是向用户提供响应的代码。
if (strResponse.StartsWith("SUCCESS"))
{
PDTHolder pdt = PDTHolder.Parse(strResponse);
Label1.Text =
string.Format("" + pdt.PayerFirstName + " " + pdt.PayerLastName + " for your payment of " + pdt.GrossTotal + " " + pdt.Currency + " option:"+pdt.OptionName+" : "+pdt.OptionOne+":"+pdt.OptionName2+ " :" + pdt.OptionTwo+"!",
pdt.PayerFirstName, pdt.PayerLastName,
pdt.PayerEmail, pdt.GrossTotal, pdt.Currency);
这是侦听器用来解析响应的类。
public class PDTHolder
{
public PDTHolder()
{
}
private double grosstotal;
public double GrossTotal
{
get { return grosstotal; }
set { grosstotal = value; }
}
private int invoicenumber;
public int InvoiceNumber
{
get { return invoicenumber; }
set { invoicenumber = value; }
}
private string paymentstatus;
public string PaymentStatus
{
get {return paymentstatus; }
set { paymentstatus = value; }
}
private string payerfirstname;
public string PayerFirstName {
get { return payerfirstname; }
set { payerfirstname = value; }
}
private double paymentfee;
public double PaymentFee {
get { return paymentfee; }
set { paymentfee = value; }
}
private string businessemail;
public string BusinessEmail {
get { return businessemail; }
set { businessemail = value; }
}
private string payeremail;
public string PayerEmail {
get { return payeremail; }
set { payeremail = value; }
}
private string txtoken;
public string TxToken {
get { return txtoken; }
set { txtoken = value; }
}
private string payerlastname;
public string PayerLastName {
get { return payerlastname; }
set { payerlastname = value; }
}
private string receiveremail;
public string ReceiverEmail {
get { return receiveremail; }
set { receiveremail = value; }
}
private string itemname;
public string ItemName {
get { return itemname; }
set { itemname = value; }
}
private string currency;
public string Currency {
get { return currency; }
set {currency = value; }
}
private string transactionid;
public string TransactionId {
get { return transactionid; }
set { transactionid = value; }
}
private string subscriberid;
public string SubscriberId {
get { return subscriberid; }
set { subscriberid = value; }
}
private string custom;
public string Custom {
get { return custom; }
set { custom = value; }
}
private string optionone;
public string OptionOne{
get{ return optionone;}
set{optionone = value;}
}
private string optionname;
public string OptionName
{
get { return optionname; }
set { optionname = value; }
}
private string optiontwo;
public string OptionTwo{
get{ return optiontwo;}
set{optiontwo = value;}
}
private string optionname2;
public string OptionName2
{
get { return optionname2; }
set { optionname2 = value; }
}
private double price;
public static PDTHolder Parse(string postData)
{
String sKey, sValue;
PDTHolder ph = new PDTHolder();
try
{
//split response into string array using whitespace delimeter
String[] StringArray = postData.Split('\n');
// NOTE:
/*
* loop is set to start at 1 rather than 0 because first
string in array will be single word SUCCESS or FAIL
Only used to verify post data
*/
// use split to split array we already have using "=" as delimiter
int i;
for (i = 1; i < StringArray.Length - 1; i++)
{
String[] StringArray1 = StringArray[i].Split('=');
sKey = StringArray1[0];
sValue = HttpUtility.UrlDecode(StringArray1[1]);
// set string vars to hold variable names using a switch
switch (sKey)
{
case "mc_gross":
ph.GrossTotal = Convert.ToDouble(sValue);
break;
case "invoice":
ph.InvoiceNumber = Convert.ToInt32(sValue);
break;
case "payment_status":
ph.PaymentStatus = Convert.ToString(sValue);
break;
case "first_name":
ph.PayerFirstName = Convert.ToString(sValue);
break;
case "mc_fee":
ph.PaymentFee = Convert.ToDouble(sValue);
break;
case "business":
ph.BusinessEmail = Convert.ToString(sValue);
break;
case "payer_email":
ph.PayerEmail = Convert.ToString(sValue);
break;
case "Tx Token":
ph.TxToken = Convert.ToString(sValue);
break;
case "last_name":
ph.PayerLastName = Convert.ToString(sValue);
break;
case "receiver_email":
ph.ReceiverEmail = Convert.ToString(sValue);
break;
case "item_name":
ph.ItemName = Convert.ToString(sValue);
break;
case "mc_currency":
ph.Currency = Convert.ToString(sValue);
break;
case "txn_id":
ph.TransactionId = Convert.ToString(sValue);
break;
case "custom":
ph.Custom = Convert.ToString(sValue);
break;
case "subscr_id":
ph.SubscriberId = Convert.ToString(sValue);
break;
case "option_selection1_1":
ph.OptionOne = Convert.ToString(sValue);
break;
case "option_name1_1":
ph.OptionName = Convert.ToString(sValue);
break;
case "option_selection1_2":
ph.OptionTwo = Convert.ToString(sValue);
break;
case "option_name1_2":
ph.OptionName2 = Convert.ToString(sValue);
break;
}
}
return ph;
}
catch (Exception ex)
{
throw ex;
}
}
}