亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何反序列化 JSON 并在 C# 中獲取值

如何反序列化 JSON 并在 C# 中獲取值

C#
開心每一天1111 2021-10-09 16:09:52
// Get the JSON response.                    string contentString = await response.Content.ReadAsStringAsync();                    Console.WriteLine(contentString);                    var rs = Newtonsoft.Json.Linq.JToken.Parse(contentString); Result rst = JsonConvert.DeserializeObject<Result>(contentString);//Here i need to get the first value in the description as it appears to be a listvar firstValue= rst.description;//And also a value from captionvar captionValue = rst.Caption public class Result    {        public Category[] categories { get; set; }        public Description description { get; set; }        public string requestId { get; set; }        public  Caption caption { get; set;}        public Metadata metadata { get; set; }        public Color color { get; set; }    }    public class Description    {        public string[] tags { get; set; }        public Caption[] captions { get; set; }    }    public class Caption    {        public string text { get; set; }        public float confidence { get; set; }    }    public class Metadata    {        public int width { get; set; }        public int height { get; set; }        public string format { get; set; }    }    public class Color    {        public string dominantColorForeground { get; set; }        public string dominantColorBackground { get; set; }        public string[] dominantColors { get; set; }        public string accentColor { get; set; }        public bool isBWImg { get; set; }    }    public class Category    {        public string name { get; set; }        public float score { get; set; }    }} 我明白我想要的很簡單,但對我來說看起來有點復雜。我已經使用了Result //rst = JsonConvert.DeserializeObject<Result>(contentString);連接并獲取響應,我已經傳入了 JSON 數據的 contentString。我只想得到我想要的價值。使用 description 作為示例會更有幫助。謝謝
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 296 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號