0
我正在開發一個通用的Windows 10應用程序。我用的WebAPI的工作和我試圖讓使用我的課的JSON序列化後調用, 的代碼如下:正在從文本框的拍攝在UI的東西JSON中的序列化返回空值
public async void PostAPI()
{
try
{
var postObject = JsonConvert.SerializeObject(thisUser);
string _serviceUrl = Constants.BaseUrl + "api/Account/Register";
HttpClient client = new HttpClient();
await client.PostAsync(new Uri(_serviceUrl), new HttpStringContent(postObject, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));
}
catch (Exception)
{
throw;
}
}
爲thisUser值像這樣:
RegisterModel thisUser = new RegisterModel();
thisUser.UserDetails = new UserDetails();
thisUser.Email = UserInputemail.Text;
thisUser.Password = "addsFABBS!2";
thisUser.ConfirmPassword = "addsFABBS!2";
thisUser.UserDetails.FullName = UserInputName.Text;
thisUser.UserDetails.Username = UserInputUserName.Text;
thisUser.UserDetails.FullName = UserInputName.Text;
thisUser.UserDetails.ICEFullName = ICEName.Text;
thisUser.UserDetails.ICEMobileNumber = int.Parse(ICEPhoneNo.Text);
thisUser.UserDetails.DoctorFullName = DocName.Text;
thisUser.UserDetails.DoctorMobileNumber = int.Parse(DocPhoneNo.Text);
postObject保持爲空。它具有值{},在此用戶中存在這些值。
的thisUser是具有以下屬性RegisterModel類的一個實例:
using System.Runtime.Serialization;
namespace APIValueSetterTest.Model
{
[DataContract]
public class RegisterModel
{
public int UserId { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
public UserDetails UserDetails { get; set; }
}
}
和用戶詳細信息類如下:
using System.Runtime.Serialization;
namespace APIValueSetterTest.Model
{
[DataContract]
public class UserDetails
{
public int UserId { get; set; }
public string FullName { get; set; }
public string Username { get; set; }
public string ICEFullName { get; set; }
public int ICEMobileNumber { get; set; }
public string DoctorFullName { get; set; }
public int DoctorMobileNumber { get; set; }
}
}
我要去哪裏錯了?