Xamarin 使用 Newtonsoft.json 序列化 Json 数据

解码:

            Task.Run(async () =>
            {
                var response = await _client.GetAsync("https://poetrydev.lightfly.cn/");
                response.EnsureSuccessStatusCode();
                var body = await response.Content.ReadAsStringAsync();
                var data = JsonConvert.DeserializeObject<ResBody<Data>>(body);
                Name = data.Data.Title;
            });

ServerInfo 定义:

using Newtonsoft.Json;

namespace poetry.Models
{
    public class Data
    {
        [JsonProperty("title")]
        public string Title { get; set; }

        [JsonProperty("version")]
        public string Version { get; set; }

        [JsonProperty("stage")]
        public string Stage { get; set; }
    }

    public class ResBody<T>
    {
        [JsonProperty("code")]
        public int Code;

        [JsonProperty("data")]
        public T Data;

        [JsonProperty("msg")]
        public string Msg;
    }
}