所以如果我调用(POST)API,我会收到这样的 json 响应:
[
{
"datum": "23.04.2023",
"wert": "400"
}
]
现在我想在我的程序中存储这两个变量,所以我创建了一个对象
public partial class Root
{
[JsonProperty("datum")]
public string datum { get; set; }
[JsonProperty("wert")]
// [JsonConverter(typeof(ParseStringConverter))]
public string wert { get; set; }
}
然后我尝试将 ReadAsString 反序列化为变量,但这不起作用,我没有得到任何值。
public async void GET_WERT(string url)
{
var client = new HttpClient();
var response = await client.PostAsync(url, null);
var jsonAsString = await response.Content.ReadAsStringAsync();
//This is not working, the MessageBox is poping out but its empty.
var variables = await response.Content.ReadFromJsonAsync<List<Root>>();
Root vars = new Root();
MessageBox.Show(vars.wert + vars.datum);
if (response.IsSuccessStatusCode)
{
}
else
{
//Error handling
}
}