本文整理汇总了C#中JsonFx.Json.JsonReader.Query方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Query方法的具体用法?C# JsonReader.Query怎么用?C# JsonReader.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonFx.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.Query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryArrayItems_OrderByThenByLast_ReturnsMultipleObjects
public void QueryArrayItems_OrderByThenByLast_ReturnsMultipleObjects()
{
// use convention over configuration on the way out
var reader = new JsonReader(new DataReaderSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase)));
// use POCO on the way out
var writer = new JsonWriter(new DataWriterSettings() { PrettyPrint=true });
string input =
@"[
{ ""personId"": 1, ""firstName"": ""Sally"", ""lastName"": ""Smith"" },
{ ""personId"": 2, ""firstName"": ""Bob"", ""lastName"": ""Smith"" },
{ ""personId"": 3, ""firstName"": ""John"", ""lastName"": ""Jones"" },
{ ""personId"": 4, ""firstName"": ""Suzie"", ""lastName"": ""Jones"" }
]";
var people = reader.Query<Person>(input);
var query =
from person in people.ArrayItems()
orderby person.LastName, person.FirstName
select person.PersonID;
Assert.Equal(1, query.Last());
const string expected =
@"[
3,
4,
2,
1
]";
string actual = writer.Write(query);
Assert.Equal(expected, actual);
}
示例2: QueryDescendants_MatchingPropertyValue_ReturnsStronglyTypedObject
public void QueryDescendants_MatchingPropertyValue_ReturnsStronglyTypedObject()
{
// input from pass1.json in test suite at http://www.json.org/JSON_checker/
const string input = @"[
""JSON Test Pattern pass1"",
{""object with 1 member"":[""array with 1 element""]},
{},
[],
-42,
true,
false,
null,
{
""integer"": 1234567890,
""real"": -9876.543210,
""e"": 0.123456789e-12,
""E"": 1.234567890E+34,
"""": 23456789012E66,
""zero"": 0,
""one"": 1,
""space"": "" "",
""quote"": ""\"""",
""backslash"": ""\\"",
""controls"": ""\b\f\n\r\t"",
""slash"": ""/ & \/"",
""alpha"": ""abcdefghijklmnopqrstuvwyz"",
""ALPHA"": ""ABCDEFGHIJKLMNOPQRSTUVWYZ"",
""digit"": ""0123456789"",
""0123456789"": ""digit"",
""special"": ""`[email protected]#$%^&*()_+-={':[,]}|;.</>?"",
""hex"": ""\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"",
""true"": true,
""false"": false,
""null"": null,
""array"":[ ],
""object"":{ },
""address"": ""50 St. James Street"",
""url"": ""http://www.JSON.org/"",
""comment"": ""// /* <!-- --"",
""# -- --> */"": "" "",
"" s p a c e d "" :[1,2 , 3
,
4 , 5 , 6 ,7 ],""compact"":[1,2,3,4,5,6,7],
""jsontext"": ""{\""object with 1 member\"":[\""array with 1 element\""]}"",
""quotes"": """ \u0022 %22 0x22 034 """,
""\/\\\""\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`[email protected]#$%^&*()_+-=[]{}|;:',./<>?""
: ""A key can be any string""
},
0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1,
1e-1,
1e00,2e+00,2e-00
,""rosebud""]";
var expected = new ComplexType
{
integer = 1234567890,
real = -9876.543210,
e = 0.123456789e-12,
E = 1.234567890E+34,
_ = 23456789012E66,
zero = 0,
one = 1,
space = " ",
quote = "\"",
backslash = "\\",
controls = "\b\f\n\r\t",
slash = "/ & /",
alpha = "abcdefghijklmnopqrstuvwyz",
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWYZ",
digit = "0123456789",
_0123456789 = "digit",
special = "`[email protected]#$%^&*()_+-={':[,]}|;.</>?",
hex = "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
@true = true,
@false = false,
@null = null,
array = new object[0],
@object = new Dictionary<string, object>(),
address = "50 St. James Street",
url = new Uri("http://www.JSON.org/"),
comment = "// /* <!-- --",
Comments = " ",
spaced = new [] { 1,2,3,4,5,6,7 },
compact = new [] { 1,2,3,4,5,6,7 },
jsontext = "{\"object with 1 member\":[\"array with 1 element\"]}",
quotes = "" \u0022 %22 0x22 034 "",
A_key_can_be_any_string = "A key can be any string"
};
var reader = new JsonReader(new DataReaderSettings(new JsonResolverStrategy()));
var source = reader.Query<ComplexType>(input);
//.........这里部分代码省略.........
示例3: QueryDescendants_WhereOrderByLast_ReturnsMultipleObjects
public void QueryDescendants_WhereOrderByLast_ReturnsMultipleObjects()
{
// respect DataContracts on the way in
var reader = new JsonReader(new DataReaderSettings(new DataContractResolverStrategy()));
// use convention over configuration on the way out
var writer = new JsonWriter(new DataWriterSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-")));
string input =
@"[
{ ""id"": 1, ""first"": ""Foo"", ""last"": ""Bar"" },
{ ""id"": 2, ""first"": ""etc."", ""last"": ""et al."" },
{ ""id"": 3, ""first"": ""Blah"", ""last"": ""Yada"" }
]";
var people = reader.Query<Person>(input);
var query =
from person in people.Descendants()
where person.PersonID == 1 || person.FirstName == "Blah"
orderby person.PersonID
select person;
Assert.Equal("Yada", query.Last().LastName);
const string expected = @"[{""person-id"":1,""first-name"":""Foo"",""last-name"":""Bar""},{""person-id"":3,""first-name"":""Blah"",""last-name"":""Yada""}]";
string actual = writer.Write(query);
Assert.Equal(expected, actual);
}