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


C# JObject.SelectToken方法代码示例

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


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

示例1: SelectTokenLinq

        public void SelectTokenLinq()
        {
            JObject o = new JObject();

            #region SelectTokenLinq
            IList<string> storeNames = o.SelectToken("Stores").Select(s => (string)s).ToList();
            // Lambton Quay
            // Willis Street

            IList<string> firstProductNames = o["Manufacturers"].Select(m => (string)m.SelectToken("Products[1].Name")).ToList();
            // null
            // Headlight Fluid

            decimal totalPrice = o["Manufacturers"].Sum(m => (decimal)m.SelectToken("Products[0].Price"));
            // 149.95
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:17,代码来源:LinqToJsonTests.cs

示例2: EvaluateIndexerOnObjectWithError

    public void EvaluateIndexerOnObjectWithError()
    {
      JObject o = new JObject(
        new JProperty("Blah", 1));

      ExceptionAssert.Throws<JsonException>(
        @"Index 1 not valid on JObject.",
        () =>
        {
          o.SelectToken("[1]", true);
        });
    }
开发者ID:royra,项目名称:ravendb,代码行数:12,代码来源:JPathTests.cs

示例3: EvaluateEmptyString

        public void EvaluateEmptyString()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            JToken t = o.SelectToken("");
            Assert.Equal(o, t);

            t = o.SelectToken("['']");
            Assert.Equal(null, t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:11,代码来源:JPathExecuteTests.cs

示例4: SelectTokenSimple

        public void SelectTokenSimple()
        {
            JObject o = new JObject();

            #region SelectTokenSimple
            string name = (string)o.SelectToken("Manufacturers[0].Name");
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:LinqToJsonTests.cs

示例5: EvaluateIndexerOnObject

    public void EvaluateIndexerOnObject()
    {
      JObject o = new JObject(
        new JProperty("Blah", 1));

      JToken t = o.SelectToken("[1]");
      Assert.IsNull(t);
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:8,代码来源:JPathTests.cs

示例6: EvaluateMissingPropertyWithError

    public void EvaluateMissingPropertyWithError()
    {
      JObject o = new JObject(
        new JProperty("Blah", 1));

      o.SelectToken("Missing", true);
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:7,代码来源:JPathTests.cs

示例7: EvaluateWildcardIndexOnObjectWithError

        public void EvaluateWildcardIndexOnObjectWithError()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            AssertException.Throws<JsonException>(() => { o.SelectToken("[*]", true); }, @"Index * not valid on JObject.");
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:7,代码来源:JPathExecuteTests.cs

示例8: EvaluateSingleProperty

    public void EvaluateSingleProperty()
    {
      JObject o = new JObject(
        new JProperty("Blah", 1));

      JToken t = o.SelectToken("Blah");
      Assert.IsNotNull(t);
      Assert.AreEqual(JTokenType.Integer, t.Type);
      Assert.AreEqual(1, (int)t);
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:10,代码来源:JPathTests.cs

示例9: EvaluateDollarTypeString

        public void EvaluateDollarTypeString()
        {
            JObject o = new JObject(
                new JProperty("$values", new JArray(1, 2, 3)));

            JToken t = o.SelectToken("$values[1]");
            Assert.Equal(2, (int)t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JPathExecuteTests.cs

示例10: QuoteName

        public void QuoteName()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            JToken t = o.SelectToken("['Blah']");
            Assert.NotNull(t);
            Assert.Equal(JTokenType.Integer, t.Type);
            Assert.Equal(1, (int)t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:10,代码来源:JPathExecuteTests.cs

示例11: EvaluateDollarString

        public void EvaluateDollarString()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            JToken t = o.SelectToken("$");
            Assert.Equal(o, t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JPathExecuteTests.cs

示例12: EvaluateWhitespaceString

        public void EvaluateWhitespaceString()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            JToken t = o.SelectToken(" ");
            Assert.Equal(o, t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JPathExecuteTests.cs

示例13: EvaluateEmptyStringWithMatchingEmptyProperty

        public void EvaluateEmptyStringWithMatchingEmptyProperty()
        {
            JObject o = new JObject(
                new JProperty(" ", 1));

            JToken t = o.SelectToken("[' ']");
            Assert.Equal(1, (int)t);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JPathExecuteTests.cs

示例14: EvaluateMissingPropertyWithError

    public void EvaluateMissingPropertyWithError()
    {
      JObject o = new JObject(
        new JProperty("Blah", 1));

      ExceptionAssert.Throws<JsonException>(
        "Property 'Missing' does not exist on JObject.",
        () =>
        {
          o.SelectToken("Missing", true);
        });
    }
开发者ID:royra,项目名称:ravendb,代码行数:12,代码来源:JPathTests.cs

示例15: EvaluateSliceOnObjectWithError

        public void EvaluateSliceOnObjectWithError()
        {
            JObject o = new JObject(
                new JProperty("Blah", 1));

            AssertException.Throws<JsonException>(() => { o.SelectToken("[:]", true); }, @"Array slice is not valid on JObject.");
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:7,代码来源:JPathExecuteTests.cs


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