当前位置: 首页>>代码示例>>C#>>正文


C# JArray.Count方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.Count方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Count方法的具体用法?C# JArray.Count怎么用?C# JArray.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JArray的用法示例。


在下文中一共展示了JArray.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFirst

        public void AddFirst()
        {
            JArray a =
            new JArray(
              5,
              new JArray(1),
              new JArray(1, 2),
              new JArray(1, 2, 3)
            );

              a.AddFirst("First");

              Assert.AreEqual("First", (string)a[0]);
              Assert.AreEqual(a, a[0].Parent);
              Assert.AreEqual(a[1], a[0].Next);
              Assert.AreEqual(5, a.Count());

              a.AddFirst("NewFirst");
              Assert.AreEqual("NewFirst", (string)a[0]);
              Assert.AreEqual(a, a[0].Parent);
              Assert.AreEqual(a[1], a[0].Next);
              Assert.AreEqual(6, a.Count());

              Assert.AreEqual(a[0], a[0].Next.Previous);
        }
开发者ID:robgreen,项目名称:nom,代码行数:25,代码来源:JTokenTests.cs

示例2: GetEducationOrganizationId

        public String GetEducationOrganizationId(JArray Links)
        {
            try
            {
                string educationOrganization = "";
                for (int index = 0; index < Links.Count(); index++)
                {
                    String relation = _authenticateUser.GetStringWithoutQuote(Links["rel"].ToString());
                    if (relation.Equals("getEducationOrganizations"))
                    {
                        String result = RestApiHelper.CallApiWithParameter(_authenticateUser.GetStringWithoutQuote(Links[index]["href"].ToString()), this._accessToken);
                        JArray educationOrganizationResponse = JArray.Parse(result);

                        for (int i = 0; i < educationOrganizationResponse.Count(); i++)
                        {
                            JToken token = educationOrganizationResponse[i];
                            educationOrganization = _authenticateUser.GetStringWithoutQuote(token["id"].ToString());
                            string organizationCategories = token["organizationCategories"].ToString();

                            if (organizationCategories.Contains("State Education Agency"))
                                educationOrganization = "State Education Agency";

                            break;
                        }
                        return educationOrganization;
                    }
                }
                return educationOrganization;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
开发者ID:jatpannu,项目名称:APP-student-insights-tool,代码行数:34,代码来源:inBloomCustom.cs

示例3: RetrievingACustomerAddressByType

        public void RetrievingACustomerAddressByType(JArray addresses)
        {
            const int CustomerId = 346760;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<int>("OwnerId") == customerId &&
                                                       addressFilter.Type.Contains(n.Value<string>("Type"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'address type for a customer' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "?Type=" + this.AddressTypes[1])).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then an address is returned".
                f(() => addresses.Count().ShouldEqual(1));
            "Then each address references the queried customer".
                f(() => addresses.ToList().ForEach(address => CustomerId.ShouldEqual(address.Value<int>("OwnerId"))));
            "Then each address references the queried type".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("Type").ShouldEqual(this.AddressTypes[1])));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:44,代码来源:RetrievingCustomerAddresses.cs

示例4: RetrievingAddressesByCity

        public void RetrievingAddressesByCity(JArray addresses)
        {
            const string City = "Denver";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("City").ToLowerInvariant().Contains(City.ToLowerInvariant())
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by city' request is sent".
                  f(() =>
                  {
                      Response = Client.GetAsync(_addressesUri + "/?City=" + City).Result;
                  });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.City == City))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(3));
            "Then each address's city references the queried city".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("City").ToLowerInvariant().ShouldContain(City.ToLowerInvariant())));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingAddresses.cs

示例5: Position

            /// <summary>
            /// Initializes a new instance of the <see cref="Position"/> class.
            /// </summary>
            /// <param name="array">
            /// The <see cref="JToken"/> holding 2 or three doubles.
            /// </param>
            /// <exception cref="ArgumentException">
            /// If <paramref name="array"/> holds less than 2 values.
            /// </exception>
            public Position(JArray array)
            {
                if (array.Count() < 2)
                {
                    throw new ArgumentException(
                    string.Format("Expected at least 2 elements, got {0}", array.Count()),
                    "array");
                }

                this.P1 = (double)array[0];
                this.P2 = (double)array[1];
                if (array.Count() > 2)
                {
                    this.P3 = (double)array[2];
                    if (array.Count() > 3)
                    {
                        this.P4 = (double)array[3];
                    }
                }
            }
开发者ID:crazymouse0,项目名称:gis,代码行数:29,代码来源:DbGeometryConverter.cs

示例6: PickIndex

 public static int PickIndex(JArray jArray)
 {
     return (int)(jArray.Count() * (new Random()).NextDouble());
 }
开发者ID:ThierryTournier,项目名称:hubiquitus4w8,代码行数:4,代码来源:HUtil.cs

示例7: GetCustomLink

        public String GetCustomLink(JArray Links)
        {
            try
            {
                //JObject HomeUrlResponse = JObject.Parse(RestApiHelper.CallApi("home", this._accessToken));
                //JArray Links = (JArray)HomeUrlResponse["links"];
                String CustomLink = "";
                for (int Index = 0; Index < Links.Count(); Index++)
                {
                    String Relation = _authenticateUser.GetStringWithoutQuote(Links[Index]["rel"].ToString());
                    if (Relation.Equals("custom"))
                        CustomLink = _authenticateUser.GetStringWithoutQuote(Links[Index]["href"].ToString());

                }
                return CustomLink;
            }
            catch (Exception Ex)
            {
                return null;
            }
        }
开发者ID:jatpannu,项目名称:APP-student-insights-tool,代码行数:21,代码来源:inBloomApi.cs

示例8: CreateWriter

        public void CreateWriter()
        {
            JArray a =
                new JArray(
                    5,
                    new JArray(1),
                    new JArray(1, 2),
                    new JArray(1, 2, 3)
                    );

            JsonWriter writer = a.CreateWriter();
            Assert.IsNotNull(writer);
            Assert.AreEqual(4, a.Count());

            writer.WriteValue("String");
            Assert.AreEqual(5, a.Count());
            Assert.AreEqual("String", (string)a[4]);

            writer.WriteStartObject();
            writer.WritePropertyName("Property");
            writer.WriteValue("PropertyValue");
            writer.WriteEnd();

            Assert.AreEqual(6, a.Count());
            Assert.IsTrue(JToken.DeepEquals(new JObject(new JProperty("Property", "PropertyValue")), a[5]));
        }
开发者ID:rogeralsing,项目名称:Newtonsoft.Json,代码行数:26,代码来源:JTokenTests.cs

示例9: Children

        public void Children()
        {
            JArray a =
                new JArray(
                    5,
                    new JArray(1),
                    new JArray(1, 2),
                    new JArray(1, 2, 3)
                    );

            Assert.AreEqual(4, a.Count());
            Assert.AreEqual(3, a.Children<JArray>().Count());
        }
开发者ID:rogeralsing,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JTokenTests.cs

示例10: AddAfterSelf

        public void AddAfterSelf()
        {
            JArray a =
                new JArray(
                    5,
                    new JArray(1),
                    new JArray(1, 2),
                    new JArray(1, 2, 3)
                    );

            a[1].AddAfterSelf("pie");

            Assert.AreEqual(5, (int)a[0]);
            Assert.AreEqual(1, a[1].Count());
            Assert.AreEqual("pie", (string)a[2]);
            Assert.AreEqual(5, a.Count());

            a[4].AddAfterSelf("lastpie");

            Assert.AreEqual("lastpie", (string)a[5]);
            Assert.AreEqual("lastpie", (string)a.Last);
        }
开发者ID:rogeralsing,项目名称:Newtonsoft.Json,代码行数:22,代码来源:JTokenTests.cs

示例11: RetrievingAllAddressesForOwnerName

        public void RetrievingAllAddressesForOwnerName(JArray addresses)
        {
            const string OwnerNameTest = "THE DILLION COMPANY";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerName.Contains(n.Value<string>("OwnerName"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'all addresses for owner name' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerName=" + OwnerNameTest)).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerName.Contains(OwnerNameTest)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then all addresses are returned for the queried owner name".
                f(() => addresses.Count().ShouldEqual(3));
            "Then each address references the expected owner name".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("OwnerName").ShouldEqual(OwnerNameTest)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:41,代码来源:RetrievingAddresses.cs

示例12: RetrievingAllAddressesForOwnerIds

        public void RetrievingAllAddressesForOwnerIds(JArray addresses)
        {
            const int OwnerId1 = 346760;
            const int OwnerId2 = 42165;

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.OwnerId.Contains(n.Value<int>("OwnerId"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for multiple owner ids' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(_addressesUri + "/?OwnerId=" + OwnerId1 + "&OwnerId=" + OwnerId2)).Result;
                });
            "Then the request is received by the API Controller".
                  f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.OwnerId.Contains(OwnerId1) && addressFilter.OwnerId.Contains(OwnerId2)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then the expected addresses are returned".
                f(() => addresses.Count().ShouldEqual(4));
            "Then each address references a queried owner".
                f(() => addresses.ToList().ForEach(address => new int[] { OwnerId1, OwnerId2 }.ShouldContain(address.Value<int>("OwnerId"))));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:42,代码来源:RetrievingAddresses.cs

示例13: RetrievingAllAddresses

 public void RetrievingAllAddresses(JArray addresses)
 {
     "Given existing addresses".
          f(() =>
          {
              MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(filter => filter == null))).Returns<dynamic>(filter =>
              {
                  return Task.FromResult<dynamic>(this.FakeAddresses);
              });
          });
     "When a GET addresses request is sent".
         f(() =>
         {
             Response = Client.GetAsync(_addressesUri).Result;
         });
     "Then the request is received by the API Controller".
         f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.IsAny<AddressesFilter>())));
     "Then a response is received by the HTTP client".
         f(() =>
         {
             Response.Content.ShouldNotBeNull();
         });
     "Then content should be returned".
         f(() =>
         {
             addresses = Response.Content.ReadAsAsync<JArray>().Result;
             addresses.ShouldNotBeNull();
         });
     "Then a '200 OK' status is returned".
         f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
     "Then all addresses are returned for all customers".
         f(() => addresses.Count().ShouldEqual(this.FakeAddresses.Count()));
 }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:33,代码来源:RetrievingAddresses.cs

示例14: RetrievingAddressesByTypes

        public void RetrievingAddressesByTypes(JArray addresses)
        {
            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[0]) && addressFilter.Type.Contains(this.AddressTypes[1])))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where addressFilter.Type.Contains(n.Value<string>("Type"))
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by multiple types' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(_addressesUri + "/?Type=" + this.AddressTypes[0] + "&Type=" + this.AddressTypes[1]).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Type.Contains(this.AddressTypes[1]) && addressFilter.Type.Contains(this.AddressTypes[1])))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(6));
            "Then each address references a queried type".
                f(() => addresses.ToList().ForEach(address => new string[] { this.AddressTypes[0], this.AddressTypes[1] }.Contains(address.Value<string>("Type"))));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:39,代码来源:RetrievingAddresses.cs

示例15: RetrievingAddressesByStreet2

        public void RetrievingAddressesByStreet2(JArray addresses)
        {
            const string Street2 = "VOGELWEIHERSTR";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2)))).Returns((AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("Street2") != null &&
                                                       n.Value<string>("Street2").Contains(addressFilter.Street2)
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses by street2' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(_addressesUri + "/?Street2=" + Street2).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetAddresses(It.Is<AddressesFilter>(addressFilter => addressFilter.Street2.Contains(Street2)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(1));
            "Then each address references the queried street2".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("Street2").ShouldContain(Street2)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:42,代码来源:RetrievingAddresses.cs


注:本文中的Newtonsoft.Json.Linq.JArray.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。