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


C# JArray.SelectTokens方法代码示例

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


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

示例1: NestedQuery

        public void NestedQuery()
        {
            JArray a = new JArray(
                new JObject(
                    new JProperty("name", "Bad Boys"),
                    new JProperty("cast", new JArray(
                        new JObject(new JProperty("name", "Will Smith"))))),
                new JObject(
                    new JProperty("name", "Independence Day"),
                    new JProperty("cast", new JArray(
                        new JObject(new JProperty("name", "Will Smith"))))),
                new JObject(
                    new JProperty("name", "The Rock"),
                    new JProperty("cast", new JArray(
                        new JObject(new JProperty("name", "Nick Cage")))))
                );

            IList<JToken> t = a.SelectTokens("[?(@.cast[?(@.name=='Will Smith')])].name").ToList();
            Assert.NotNull(t);
            Assert.Equal(2, t.Count);
            Assert.Equal("Bad Boys", (string)t[0]);
            Assert.Equal("Independence Day", (string)t[1]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:23,代码来源:JPathExecuteTests.cs

示例2: GreaterQueryBigInteger

        public void GreaterQueryBigInteger()
        {
            JArray a = new JArray(
                new JObject(new JProperty("hi", new BigInteger(1))),
                new JObject(new JProperty("hi", new BigInteger(2))),
                new JObject(new JProperty("hi", new BigInteger(3))));

            IList<JToken> t = a.SelectTokens("[ ?( @.hi > 1 ) ]").ToList();
            Assert.NotNull(t);
            Assert.Equal(2, t.Count);
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 2)), t[0]));
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 3)), t[1]));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:13,代码来源:JPathExecuteTests.cs

示例3: GreaterOrEqualQuery

        public void GreaterOrEqualQuery()
        {
            JArray a = new JArray(
                new JObject(new JProperty("hi", 1)),
                new JObject(new JProperty("hi", 2)),
                new JObject(new JProperty("hi", 2.0)),
                new JObject(new JProperty("hi", 3)));

            IList<JToken> t = a.SelectTokens("[ ?( @.hi >= 1 ) ]").ToList();
            Assert.NotNull(t);
            Assert.Equal(4, t.Count);
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 1)), t[0]));
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 2)), t[1]));
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 2.0)), t[2]));
            Assert.True(JToken.DeepEquals(new JObject(new JProperty("hi", 3)), t[3]));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:16,代码来源:JPathExecuteTests.cs

示例4: NoPathQuery

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

            IList<JToken> t = a.SelectTokens("[ ?( @ > 1 ) ]").ToList();
            Assert.NotNull(t);
            Assert.Equal(2, t.Count);
            Assert.Equal(2, (int)t[0]);
            Assert.Equal(3, (int)t[1]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:10,代码来源:JPathExecuteTests.cs

示例5: MultipleQueries

        public void MultipleQueries()
        {
            JArray a = new JArray(1, 2, 3, 4, 5, 6, 7, 8, 9);

            // json path does item based evaluation - http://www.sitepen.com/blog/2008/03/17/jsonpath-support/
            // first query resolves array to ints
            // int has no children to query
            IList<JToken> t = a.SelectTokens("[?(@ <> 1)][?(@ <> 4)][?(@ < 7)]").ToList();
            Assert.NotNull(t);
            Assert.Equal(0, t.Count);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:11,代码来源:JPathExecuteTests.cs

示例6: EvaluateWildcardScanNestResults

        public void EvaluateWildcardScanNestResults()
        {
            JObject o1 = new JObject { { "Name", 1 } };
            JObject o2 = new JObject { { "Name", 2 } };
            JObject o3 = new JObject { { "Name", new JObject { { "Name", new JArray(3) } } } };
            JArray a = new JArray(o1, o2, o3);

            IList<JToken> t = a.SelectTokens("$..*").ToList();
            Assert.NotNull(t);
            Assert.Equal(9, t.Count);

            Assert.True(JToken.DeepEquals(a, t[0]));
            Assert.True(JToken.DeepEquals(o1, t[1]));
            Assert.Equal(1, (int)t[2]);
            Assert.True(JToken.DeepEquals(o2, t[3]));
            Assert.Equal(2, (int)t[4]);
            Assert.True(JToken.DeepEquals(o3, t[5]));
            Assert.True(JToken.DeepEquals(new JObject { { "Name", new JArray(3) } }, t[6]));
            Assert.True(JToken.DeepEquals(new JArray(3), t[7]));
            Assert.Equal(3, (int)t[8]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:21,代码来源:JPathExecuteTests.cs

示例7: NotEqualsQuery

        public void NotEqualsQuery()
        {
            JArray a = new JArray(
                new JArray(new JObject(new JProperty("hi", "ho"))),
                new JArray(new JObject(new JProperty("hi", "ha"))));

            IList<JToken> t = a.SelectTokens("[ ?( @..hi <> 'ha' ) ]").ToList();
            Assert.NotNull(t);
            Assert.Equal(1, t.Count);
            Assert.True(JToken.DeepEquals(new JArray(new JObject(new JProperty("hi", "ho"))), t[0]));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:11,代码来源:JPathExecuteTests.cs

示例8: EvaluateWildcardScan

        public void EvaluateWildcardScan()
        {
            JObject o1 = new JObject { { "Name", 1 } };
            JObject o2 = new JObject { { "Name", 2 } };
            JArray a = new JArray(o1, o2);

            IList<JToken> t = a.SelectTokens("$..*").ToList();
            Assert.NotNull(t);
            Assert.Equal(5, t.Count);
            Assert.True(JToken.DeepEquals(a, t[0]));
            Assert.True(JToken.DeepEquals(o1, t[1]));
            Assert.Equal(1, (int)t[2]);
            Assert.True(JToken.DeepEquals(o2, t[3]));
            Assert.Equal(2, (int)t[4]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:15,代码来源:JPathExecuteTests.cs

示例9: EvaluateScan

        public void EvaluateScan()
        {
            JObject o1 = new JObject { { "Name", 1 } };
            JObject o2 = new JObject { { "Name", 2 } };
            JArray a = new JArray(o1, o2);

            IList<JToken> t = a.SelectTokens("$..Name").ToList();
            Assert.NotNull(t);
            Assert.Equal(2, t.Count);
            Assert.Equal(1, (int)t[0]);
            Assert.Equal(2, (int)t[1]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:12,代码来源:JPathExecuteTests.cs

示例10: EvaluateArrayMultipleIndexes

        public void EvaluateArrayMultipleIndexes()
        {
            JArray a = new JArray(1, 2, 3, 4);

            IEnumerable<JToken> t = a.SelectTokens("[1,2,0]");
            Assert.NotNull(t);
            Assert.Equal(3, t.Count());
            Assert.Equal(2, (int)t.ElementAt(0));
            Assert.Equal(3, (int)t.ElementAt(1));
            Assert.Equal(1, (int)t.ElementAt(2));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:11,代码来源:JPathExecuteTests.cs

示例11: EvaluateWildcardArray

        public void EvaluateWildcardArray()
        {
            JArray a = new JArray(1, 2, 3, 4);

            List<JToken> t = a.SelectTokens("[*]").ToList();
            Assert.NotNull(t);
            Assert.Equal(4, t.Count);
            Assert.Equal(1, (int)t[0]);
            Assert.Equal(2, (int)t[1]);
            Assert.Equal(3, (int)t[2]);
            Assert.Equal(4, (int)t[3]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:12,代码来源:JPathExecuteTests.cs

示例12: EvaluateArraySlice

        public void EvaluateArraySlice()
        {
            JArray a = new JArray(1, 2, 3, 4, 5, 6, 7, 8, 9);
            IList<JToken> t = null;

            t = a.SelectTokens("[-3:]").ToList();
            Assert.Equal(3, t.Count);
            Assert.Equal(7, (int)t[0]);
            Assert.Equal(8, (int)t[1]);
            Assert.Equal(9, (int)t[2]);

            t = a.SelectTokens("[-1:-2:-1]").ToList();
            Assert.Equal(1, t.Count);
            Assert.Equal(9, (int)t[0]);

            t = a.SelectTokens("[-2:-1]").ToList();
            Assert.Equal(1, t.Count);
            Assert.Equal(8, (int)t[0]);

            t = a.SelectTokens("[1:1]").ToList();
            Assert.Equal(0, t.Count);

            t = a.SelectTokens("[1:2]").ToList();
            Assert.Equal(1, t.Count);
            Assert.Equal(2, (int)t[0]);

            t = a.SelectTokens("[::-1]").ToList();
            Assert.Equal(9, t.Count);
            Assert.Equal(9, (int)t[0]);
            Assert.Equal(8, (int)t[1]);
            Assert.Equal(7, (int)t[2]);
            Assert.Equal(6, (int)t[3]);
            Assert.Equal(5, (int)t[4]);
            Assert.Equal(4, (int)t[5]);
            Assert.Equal(3, (int)t[6]);
            Assert.Equal(2, (int)t[7]);
            Assert.Equal(1, (int)t[8]);

            t = a.SelectTokens("[::-2]").ToList();
            Assert.Equal(5, t.Count);
            Assert.Equal(9, (int)t[0]);
            Assert.Equal(7, (int)t[1]);
            Assert.Equal(5, (int)t[2]);
            Assert.Equal(3, (int)t[3]);
            Assert.Equal(1, (int)t[4]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:46,代码来源:JPathExecuteTests.cs


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