<small id='JSjJX'></small><noframes id='JSjJX'>

    <legend id='JSjJX'><style id='JSjJX'><dir id='JSjJX'><q id='JSjJX'></q></dir></style></legend>
    • <bdo id='JSjJX'></bdo><ul id='JSjJX'></ul>
    <i id='JSjJX'><tr id='JSjJX'><dt id='JSjJX'><q id='JSjJX'><span id='JSjJX'><b id='JSjJX'><form id='JSjJX'><ins id='JSjJX'></ins><ul id='JSjJX'></ul><sub id='JSjJX'></sub></form><legend id='JSjJX'></legend><bdo id='JSjJX'><pre id='JSjJX'><center id='JSjJX'></center></pre></bdo></b><th id='JSjJX'></th></span></q></dt></tr></i><div id='JSjJX'><tfoot id='JSjJX'></tfoot><dl id='JSjJX'><fieldset id='JSjJX'></fieldset></dl></div>

    1. <tfoot id='JSjJX'></tfoot>

      从 Json 字符串中提取数据

      时间:2023-08-22
      <tfoot id='G9tUq'></tfoot>
      <legend id='G9tUq'><style id='G9tUq'><dir id='G9tUq'><q id='G9tUq'></q></dir></style></legend>

        <small id='G9tUq'></small><noframes id='G9tUq'>

        <i id='G9tUq'><tr id='G9tUq'><dt id='G9tUq'><q id='G9tUq'><span id='G9tUq'><b id='G9tUq'><form id='G9tUq'><ins id='G9tUq'></ins><ul id='G9tUq'></ul><sub id='G9tUq'></sub></form><legend id='G9tUq'></legend><bdo id='G9tUq'><pre id='G9tUq'><center id='G9tUq'></center></pre></bdo></b><th id='G9tUq'></th></span></q></dt></tr></i><div id='G9tUq'><tfoot id='G9tUq'></tfoot><dl id='G9tUq'><fieldset id='G9tUq'></fieldset></dl></div>
          <tbody id='G9tUq'></tbody>

            • <bdo id='G9tUq'></bdo><ul id='G9tUq'></ul>
                本文介绍了从 Json 字符串中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我得到了一个包含 Json 的字符串.它看起来像这样:

                I got a string containing Json. It looks like this:

                "status_code":200,
                "status_txt":"OK",
                "data":
                {
                   "img_name":"D9Y3z.png",
                   "img_url":"http://s1.uploads.im/D9Y3z.png",
                   "img_view":"http://uploads.im/D9Y3z.png",
                   "img_width":"167",
                   "img_height":"288",
                   "img_attr":"width="167" height="288"",
                   "img_size":"36.1 KB",
                   "img_bytes":36981,
                   "thumb_url":"http://s1.uploads.im/t/D9Y3z.png",
                   "thumb_width":360,
                   "thumb_height":360,
                   "source":"http://www.google.com/images/srpr/nav_logo66.png",
                   "resized":"0",
                   "delete_key":"df149b075ab68c38"
                }
                

                我正在尝试获取img_url".我已经安装了 Json.NET,我在这里发现了类似的问题..

                I am trying to get a hold of the "img_url". I have Json.NET installed and I´ve found similar questions here..

                例如这样的:

                JObject o = JObject.Parse("{'People':[{'Name':'Jeff'},{'Name':'Joe'}]}");
                
                // get name token of first person and convert to a string
                string name = (string)o.SelectToken("People[0].Name");
                

                就我而言,我将 ("People[0].Name") 更改为 ("img_url"),("img_url[0]) etc..没有运气

                In my case I changed ("People[0].Name") to ("img_url"),("img_url[0]) etc..no luck

                这是我现在的代码:

                public string tempJson { get; set; }
                public ActionResult SaveUploadedFile(string test)
                {
                    using (WebResponse wrs = wrq.GetResponse())
                    using (Stream stream = wrs.GetResponseStream())
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string json = reader.ReadToEnd();
                        tempJson = json;
                    }
                }
                

                在提取值之前,我是否必须对字符串进行处理?谢谢!

                Do I have to do something with the string before I can extract the value? Thanks!

                推荐答案

                img_url 不是根对象的属性 - 它是 data 对象的属性:

                img_url is not a property of root object - it's a property of data object:

                var obj = JObject.Parse(json);
                var url = (string)obj["data"]["img_url"]; // http://s1.uploads.im/D9Y3z.png
                

                另一种选择:

                var url = (string)obj.SelectToken("data.img_url");
                

                这篇关于从 Json 字符串中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:JSON.Net Xml 序列化误解了数组 下一篇:Newtonsoft JsonSerializer - 小写属性和字典

                相关文章

                最新文章

                  1. <tfoot id='mT0yS'></tfoot>

                  2. <i id='mT0yS'><tr id='mT0yS'><dt id='mT0yS'><q id='mT0yS'><span id='mT0yS'><b id='mT0yS'><form id='mT0yS'><ins id='mT0yS'></ins><ul id='mT0yS'></ul><sub id='mT0yS'></sub></form><legend id='mT0yS'></legend><bdo id='mT0yS'><pre id='mT0yS'><center id='mT0yS'></center></pre></bdo></b><th id='mT0yS'></th></span></q></dt></tr></i><div id='mT0yS'><tfoot id='mT0yS'></tfoot><dl id='mT0yS'><fieldset id='mT0yS'></fieldset></dl></div>
                      <bdo id='mT0yS'></bdo><ul id='mT0yS'></ul>

                    <small id='mT0yS'></small><noframes id='mT0yS'>

                  3. <legend id='mT0yS'><style id='mT0yS'><dir id='mT0yS'><q id='mT0yS'></q></dir></style></legend>