0
當我將請求發送到我的控制器,由於某種原因,將其分配給對象的所有空值:爲什麼在控制器方法中將具體對象設置爲null?
我發送請求如下:
{
"createCustomerPaymentProfileRequest": {
"merchantAuthentication": {
"name": "3efsw3sd66",
"transactionKey": "7m444433G"
},
"customerProfileId": "10000",
"paymentProfile": {
"billTo": {
"firstName": "John",
"lastName": "Doe",
"address": "123 Main St.",
"city": "Bellevue",
"state": "WA",
"zip": "98004",
"country": "USA",
"phoneNumber": "000-000-0000"
},
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "2023-12"
}
},
"defaultPaymentProfile": false
},
"validationMode": "liveMode"
}
}
這是我如何從發行郵遞員請求:
爲什麼我的請求的屬性設置爲null?
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="AnetApi/xml/v1/schema/AnetApiSchema.xsd", IsNullable=false)]
public partial class createCustomerPaymentProfileRequest : ANetApiRequest {
/// <remarks/>
public string customerProfileId;
/// <remarks/>
public customerPaymentProfileType paymentProfile;
/// <remarks/>
public validationModeEnum validationMode;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool validationModeSpecified;
}
其母公司被定義爲:
作爲類被定義
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
public partial class ANetApiRequest {
/// <remarks/>
public merchantAuthenticationType merchantAuthentication;
/// <remarks/>
public string clientId;
/// <remarks/>
public string refId;
}
而屬性中的一個被定義爲:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="AnetApi/xml/v1/schema/AnetApiSchema.xsd")]
public partial class merchantAuthenticationType {
/// <remarks/>
public string name;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("accessToken", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("clientKey", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("fingerPrint", typeof(fingerPrintType))]
[System.Xml.Serialization.XmlElementAttribute("impersonationAuthentication", typeof(impersonationAuthenticationType))]
[System.Xml.Serialization.XmlElementAttribute("password", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("sessionToken", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("transactionKey", typeof(string))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName;
/// <remarks/>
public string mobileDeviceId;
}
和另一個:
public partial class customerPaymentProfileType : customerPaymentProfileBaseType {
/// <remarks/>
public paymentType payment;
/// <remarks/>
public driversLicenseType driversLicense;
/// <remarks/>
public string taxId;
/// <remarks/>
public bool defaultPaymentProfile;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool defaultPaymentProfileSpecified;
}
使用'[FromBody]'屬性試試看解決了這個問題。 'Go([FromBody] ParameterType request)' – Nkosi
nope它沒有https://lh3.googleusercontent.com/-OvsOhha2Q3k/WZJViRz1QOI/AAAAAAAADeM/qjZFl246FI4W-kvOxfRz55F3rFrjfEY8wCHMYCw/s0/devenv_2017-08-14_20-59-35.png –
顯示課程。需要能夠比較JSON類到映射到 – Nkosi