[英]RestSharp not deserializing a string (always null)
我目前嘗試從 RestSharp PostAsync 調用中獲取序列化響應,例如
var responseData = Client.PostAsync<Data>(request).Result;
現在,這就是我收到的:
{
"status":1,
"success":"message transmitted",
"available":19215,
"message_ids":"26684730:56798"
}
這是“數據”class:
public class Data
{
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("success")]
public string Success { get; set; }
[JsonProperty("available")]
public int Available { get; set; }
[JsonProperty("message_ids")]
public string MessageIds { get; set; }
[JsonProperty("error")]
public string Error { get; set; }
}
我不知道為什么,但是屬性 message_ids 總是 null?: 這可能是由字符串中的, 引起的嗎? 我的這是RestSharp中的一個錯誤?
這是“數據”的樣子:
對於restsharp,您需要 JsonPropertyName 屬性
[JsonPropertyName("message_ids")]
public string MessageIds { get; set; }
或者如果你想使用 JsonProperty 你將不得不使用 Newtonsoft.Json
var response = client.ExecuteAsync(request).Result;
//if you have async method better to use
var response = await client.ExecuteAsync(request);
Data data = JsonConvert.DeserializeObject<Data>(response.Content);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.