本文整理汇总了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
}
示例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);
});
}
示例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);
}
示例4: SelectTokenSimple
public void SelectTokenSimple()
{
JObject o = new JObject();
#region SelectTokenSimple
string name = (string)o.SelectToken("Manufacturers[0].Name");
#endregion
}
示例5: EvaluateIndexerOnObject
public void EvaluateIndexerOnObject()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("[1]");
Assert.IsNull(t);
}
示例6: EvaluateMissingPropertyWithError
public void EvaluateMissingPropertyWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
o.SelectToken("Missing", true);
}
示例7: EvaluateWildcardIndexOnObjectWithError
public void EvaluateWildcardIndexOnObjectWithError()
{
JObject o = new JObject(
new JProperty("Blah", 1));
AssertException.Throws<JsonException>(() => { o.SelectToken("[*]", true); }, @"Index * not valid on JObject.");
}
示例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);
}
示例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);
}
示例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);
}
示例11: EvaluateDollarString
public void EvaluateDollarString()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken("$");
Assert.Equal(o, t);
}
示例12: EvaluateWhitespaceString
public void EvaluateWhitespaceString()
{
JObject o = new JObject(
new JProperty("Blah", 1));
JToken t = o.SelectToken(" ");
Assert.Equal(o, t);
}
示例13: EvaluateEmptyStringWithMatchingEmptyProperty
public void EvaluateEmptyStringWithMatchingEmptyProperty()
{
JObject o = new JObject(
new JProperty(" ", 1));
JToken t = o.SelectToken("[' ']");
Assert.Equal(1, (int)t);
}
示例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);
});
}
示例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.");
}