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


C# JsonReader.Query方法代码示例

本文整理汇总了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);
		}
开发者ID:RocketChicken,项目名称:jsonfx,代码行数:35,代码来源:QueryEngineTests.cs

示例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"": ""&#34; \u0022 %22 0x22 034 &#x22;"",
        ""\/\\\""\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 = "&#34; \u0022 %22 0x22 034 &#x22;",
				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);
//.........这里部分代码省略.........
开发者ID:RocketChicken,项目名称:jsonfx,代码行数:101,代码来源:QueryEngineTests.cs

示例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);
		}
开发者ID:RocketChicken,项目名称:jsonfx,代码行数:29,代码来源:QueryEngineTests.cs


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