• [c#]如何访问 JArray 的元素


    JArray 格式文件。
        public void TestJson()
        {
            var jsonString = @"{""trends"": [
                  {
                    ""name"": ""Croke Park II"",
                    ""url"": ""http://twitter.com/search?q=%22Croke+Park+II%22"",
                    ""promoted_content"": null,
                    ""query"": ""%22Croke+Park+II%22"",
                    ""events"": null
                  },
                  {
                    ""name"": ""Siptu"",
                    ""url"": ""http://twitter.com/search?q=Siptu"",
                    ""promoted_content"": null,
                    ""query"": ""Siptu"",
                    ""events"": null
                  },
                  {
                    ""name"": ""#HNCJ"",
                    ""url"": ""http://twitter.com/search?q=%23HNCJ"",
                    ""promoted_content"": null,
                    ""query"": ""%23HNCJ"",
                    ""events"": null
                  },
                  {
                    ""name"": ""Boston"",
                    ""url"": ""http://twitter.com/search?q=Boston"",
                    ""promoted_content"": null,
                    ""query"": ""Boston"",
                    ""events"": null
                  },
                  {
                    ""name"": ""#prayforboston"",
                    ""url"": ""http://twitter.com/search?q=%23prayforboston"",
                    ""promoted_content"": null,
                    ""query"": ""%23prayforboston"",
                    ""events"": null
                  },
                  {
                    ""name"": ""#TheMrsCarterShow"",
                    ""url"": ""http://twitter.com/search?q=%23TheMrsCarterShow"",
                    ""promoted_content"": null,
                    ""query"": ""%23TheMrsCarterShow"",
                    ""events"": null
                  },
                  {
                    ""name"": ""#Raw"",
                    ""url"": ""http://twitter.com/search?q=%23Raw"",
                    ""promoted_content"": null,
                    ""query"": ""%23Raw"",
                    ""events"": null
                  },
                  {
                    ""name"": ""Iran"",
                    ""url"": ""http://twitter.com/search?q=Iran"",
                    ""promoted_content"": null,
                    ""query"": ""Iran"",
                    ""events"": null
                  },
                  {
                    ""name"": ""#gaa"",
                    ""url"": ""http://twitter.com/search?q=%23gaa"",
                    ""promoted_content"": null,
                    ""query"": ""gaa"",
                    ""events"": null
                  },
                  {
                    ""name"": ""Facebook"",
                    ""url"": ""http://twitter.com/search?q=Facebook"",
                    ""promoted_content"": null,
                    ""query"": ""Facebook"",
                    ""events"": null
                  }]}";
    
            var twitterObject = JToken.Parse(jsonString);
            var trendsArray = twitterObject.Children<JProperty>().FirstOrDefault(x => x.Name == "trends").Value;
    
    
            foreach (var item in trendsArray.Children())
            {
                var itemProperties = item.Children<JProperty>();
                //you could do a foreach or a linq here depending on what you need to do exactly with the value
                var myElement = itemProperties.FirstOrDefault(x => x.Name == "url");
                var myElementValue = myElement.Value; ////This is a JValue type
            }
        }

     参考:

    http://www.itstrike.cn/Question/40c3d9b3-022e-4362-b125-29a5339ef0e1.html

    http://stackoverflow.com/questions/16045569/how-to-access-elements-of-a-jarray

  • 相关阅读:
    使用RAID与LVM磁盘阵列技术。
    CentOS7使用firewalld打开关闭防火墙与端口
    centos7 firewalled
    CentOS 7 firewalld vsftpd开放端口
    ftp的主动模式active mode和被动模式 passive mode的配置和区别
    ftp 长传报错553 可能是选的目录不对
    web控制树莓派摄像头
    TensorFlow.js入门:一维向量的学习
    Getting Started with TensorFlow.js
    搭建PHP开发环境(XAMPP+PhpStorm)
  • 原文地址:https://www.cnblogs.com/CeleryCabbage/p/6806089.html
Copyright © 2020-2023  润新知