从属性获取值并序列化它
本文关键字:序列化 获取 从属性 | 更新日期: 2023-09-27 18:18:10
我正在为UWP编写应用程序。
我有这个代码
private List<RootObject> ordersList;
public List<RootObject> OrdersList
{
get { return ordersList; }
set
{
ordersList = value;
OnPropertyChanged();
}
}
private RootObject ordersChange;
public RootObject OrdersChange
{
get { return ordersChange; }
set
{
ordersChange = value;
OnPropertyChanged();
}
}
当我点击按钮值写入到ordersChange
和set
值。
我需要获取值,序列化并通过post请求发送。
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(@"http://api.simplegames.com.ua");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("utf-8"));
string endpoint = @"/post_from_local.php";
try
{
HttpContent content = new StringContent(JsonConvert.SerializeObject(*****), Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(endpoint, content);
其中***
为值。我怎么能做到呢?
谢谢你的帮助
如果你想发布OrdersChange,你可以这样做。
var json = JsonConvert.SerializeObject(viewModelInstance.OrdersChange);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(apiUrl, content);