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

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

部分反序列化 JSON 以僅獲取必需的屬性

部分反序列化 JSON 以僅獲取必需的屬性

C#
鳳凰求蠱 2021-10-31 19:04:16
我在 JSON 格式中得到了很大的響應,我只需要 2 個字符串,這是我的 JSON 文件,我在其中減少了更好的閱讀{  "cdn_url": "https://f.vimeocdn.com",  "vimeo_api_url": "api.vimeo.com",  "request": {    "files": {      "progressive": [        {          "profile": 164,          "width": 622,          "mime": "video/mp4",          "fps": 25,          "url": "1047326445.mp4",          "cdn": "akamai_interconnect",          "quality": "360p",          "id": 1047326445,          "origin": "gcs",          "height": 360        },        {          "profile": 165,          "width": 932,          "mime": "video/mp4",          "fps": 25,          "url": "1047326437.mp4",          "cdn": "akamai_interconnect",          "quality": "540p",          "id": 1047326437,          "origin": "gcs",          "height": 540        }      ]    }  },  "video": {    "version": {      "current": null,      "available": null    },    "height": 540,    "duration": 401,    "thumbs": {      "640": "712851375_640.jpg",      "960": "712851375_960.jpg",      "base": "712851375"    },    "id": 279550927,    "default_to_hd": 0,    "url": null,    "privacy": "disable",    "unlisted_hash": null  }}我從中刪除了很多對象以便更好地閱讀。我想要“url”:“1047326445.mp4”,來自“漸進式數組和來自視頻對象中的“640”變量的字符串。
查看完整描述

2 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

我通過這個得到了渴望的結果,


        string json = null;


        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlJSONcall);

        HttpWebResponse response = null;


        try

        {

            response = (HttpWebResponse)request.GetResponse();

            var responseStream = response.GetResponseStream();


            if ((responseStream != null) && responseStream.CanRead)

            {

                using (var reader = new System.IO.StreamReader(responseStream))

                {

                    json = reader.ReadToEnd();


                }

            }

        }

        finally

        {

            if (response != null)

            {

                response.Close();

            }

        }


        var datao = (JObject)JsonConvert.DeserializeObject(json);

        //LBresponse.Text = data.ToString();

        string urll = (string)datao["request"]["files"]["progressive"][0]["url"];


        string thumbnailImage = (string)datao["video"]["thumbs"]["640"];

        LBresponse.Text = urll.ToString();

        lbltumb.Text = thumbnailImage.ToString();

    }



查看完整回答
反對 回復 2021-10-31
  • 2 回答
  • 0 關注
  • 261 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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