• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SimpleJsonSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SimpleJsonSerializer的典型用法代码示例。如果您正苦于以下问题:C# SimpleJsonSerializer类的具体用法?C# SimpleJsonSerializer怎么用?C# SimpleJsonSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SimpleJsonSerializer类属于命名空间,在下文中一共展示了SimpleJsonSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: HandleUnicodeCharacters

            public void HandleUnicodeCharacters()
            {
                const string backspace = "\b";
                const string tab = "\t";

                var sb = new StringBuilder();
                sb.Append("My name has Unicode characters");
                Enumerable.Range(0, 19).Select(e => System.Convert.ToChar(e))
                .Aggregate(sb, (a, b) => a.Append(b));
                sb.Append(backspace).Append(tab);
                var data = sb.ToString();

                var json = new SimpleJsonSerializer().Serialize(data);
                var lastTabCharacter = json
                    .Reverse()
                    .Skip(1)
                    .Take(2)
                    .Reverse()
                    .Aggregate(new StringBuilder(), (a, b) => a.Append(b));

                var deserializeData = new SimpleJsonSerializer().Deserialize<string>(json);

                Assert.True(lastTabCharacter.ToString().Equals("\\t"));
                Assert.Equal(data, deserializeData);
            }
开发者ID:daveaglick,项目名称:octokit.net,代码行数:25,代码来源:SimpleJsonSerializerTests.cs


示例2: CanSerialize

        public void CanSerialize()
        {
            var expected = "{\"name\":\"Hello-World\"," +
                           "\"description\":\"This is your first repository\"," +
                           "\"homepage\":\"https://github.com\"," +
                           "\"private\":true," +
                           "\"has_issues\":true," +
                           "\"has_wiki\":true," +
                           "\"has_downloads\":true}";

            var update = new RepositoryUpdate
            {
                Name = "Hello-World",
                Description = "This is your first repository",
                Homepage = "https://github.com",
                Private = true,
                HasIssues = true,
                HasWiki = true,
                HasDownloads = true
            };

            var json = new SimpleJsonSerializer().Serialize(update);

            Assert.Equal(expected, json);
        }
开发者ID:RadicalLove,项目名称:octokit.net,代码行数:25,代码来源:RepositoryUpdateTests.cs


示例3: PlainScript

 public PlainScript(IAsset asset, Bundle bundle, IAmdConfiguration modules)
     : base(asset, bundle)
 {
     this.modules = modules;
     jsonSerializer = new SimpleJsonSerializer();
     asset.AddAssetTransformer(this);
 }
开发者ID:joshperry,项目名称:cassette,代码行数:7,代码来源:PlainScript.cs


示例4: PlainScript

 public PlainScript(IAsset asset, Bundle bundle, IModuleInitializer modules,string baseUrl = null)
     : base(asset, bundle, baseUrl)
 {
     this.modules = modules;
     jsonSerializer = new SimpleJsonSerializer();
     asset.AddAssetTransformer(this);
 }
开发者ID:joplaal,项目名称:cassette,代码行数:7,代码来源:PlainScript.cs


示例5: GetShowcases

 public async Task<List<Showcase>> GetShowcases()
 {
     var url = string.Format(ShowcaseUrl, string.Empty);
     var data = await BlobCache.LocalMachine.DownloadUrl(url, absoluteExpiration: DateTimeOffset.Now.AddDays(1));
     var serializer = new SimpleJsonSerializer();
     return serializer.Deserialize<List<Showcase>>(Encoding.UTF8.GetString(data));
 }
开发者ID:memopower,项目名称:RepoStumble,代码行数:7,代码来源:ShowcaseRepository.cs


示例6: UsesRubyCasing

            public void UsesRubyCasing()
            {
                var item = new Sample { Id = 42, FirstName = "Phil", IsSomething = true, Private = true };

                var json = new SimpleJsonSerializer().Serialize(item);

                Assert.Equal("{\"id\":42,\"first_name\":\"Phil\",\"is_something\":true,\"private\":true}", json);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:8,代码来源:SimpleJsonSerializerTests.cs


示例7: GetTrendingRepositories

 public async Task<List<Octokit.Repository>> GetTrendingRepositories(string since, string language = null)
 {
     var query = "?since=" + since;
     if (!string.IsNullOrEmpty(language))
         query += string.Format("&language={0}", language);
     var data = await BlobCache.LocalMachine.DownloadUrl(TrendingUrl + query, absoluteExpiration: DateTimeOffset.Now.AddHours(1));
     var serializer = new SimpleJsonSerializer();
     return serializer.Deserialize<List<Octokit.Repository>>(Encoding.UTF8.GetString(data));
 }
开发者ID:memopower,项目名称:RepoStumble,代码行数:9,代码来源:TrendingRepository.cs


示例8: UnderstandsRubyCasing

            public void UnderstandsRubyCasing()
            {
                const string json = "{\"id\":42,\"first_name\":\"Phil\",\"is_something\":true,\"private\":true}";

                var sample = new SimpleJsonSerializer().Deserialize<Sample>(json);

                Assert.Equal(42, sample.Id);
                Assert.Equal("Phil", sample.FirstName);
                Assert.True(sample.IsSomething);
                Assert.True(sample.Private);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:11,代码来源:SimpleJsonSerializerTests.cs


示例9: GetTrendingRepositories

        public async Task<IList<GitHubSharp.Models.RepositoryModel>> GetTrendingRepositories(string since, string language = null)
        {
            var query = "?since=" + since;
            if (!string.IsNullOrEmpty(language))
                query += string.Format("&language={0}", language);

            var client = new HttpClient();
            var serializer = new SimpleJsonSerializer();
            var msg = await client.GetAsync(TrendingUrl + query).ConfigureAwait(false);
            var content = await msg.Content.ReadAsStringAsync().ConfigureAwait(false);
            return serializer.Deserialize<List<GitHubSharp.Models.RepositoryModel>>(content);
        }
开发者ID:RaineriOS,项目名称:CodeHub,代码行数:12,代码来源:TrendingRepository.cs


示例10: CanBeDeserialized

        public void CanBeDeserialized()
        {
            var serializer = new SimpleJsonSerializer();

            var apiError = serializer.Deserialize<ApiError>(json);

            Assert.Equal("Validation Failed", apiError.Message);
            Assert.Equal(1, apiError.Errors.Count);
            Assert.Equal("Issue", apiError.Errors[0].Resource);
            Assert.Equal("title", apiError.Errors[0].Field);
            Assert.Equal("missing_field", apiError.Errors[0].Code);
        }
开发者ID:cloudRoutine,项目名称:octokit.net,代码行数:12,代码来源:ApiErrorTests.cs


示例11: OmitsPropertiesWithNullValue

            public void OmitsPropertiesWithNullValue()
            {
                var item = new
                {
                    Object = (object)null,
                    NullableInt = (int?)null,
                    NullableBool = (bool?)null
                };

                var json = new SimpleJsonSerializer().Serialize(item);

                Assert.Equal("{}", json);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:13,代码来源:SimpleJsonSerializerTests.cs


示例12: DoesNotOmitsNullablePropertiesWithAValue

            public void DoesNotOmitsNullablePropertiesWithAValue()
            {
                var item = new
                {
                    Object = new { Id = 42 },
                    NullableInt = (int?)1066,
                    NullableBool = (bool?)true
                };

                var json = new SimpleJsonSerializer().Serialize(item);

                Assert.Equal("{\"object\":{\"id\":42},\"nullable_int\":1066,\"nullable_bool\":true}", json);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:13,代码来源:SimpleJsonSerializerTests.cs


示例13: HandlesMixingNullAndNotNullData

            public void HandlesMixingNullAndNotNullData()
            {
                var item = new
                {
                    Int = 42,
                    Bool = true,
                    NullableInt = (int?)null,
                    NullableBool = (bool?)null
                };

                var json = new SimpleJsonSerializer().Serialize(item);

                Assert.Equal("{\"int\":42,\"bool\":true}", json);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:14,代码来源:SimpleJsonSerializerTests.cs


示例14: CanBeDeserializedWithNullPrivateGistsDiskUsageAndCollaborators

    public void CanBeDeserializedWithNullPrivateGistsDiskUsageAndCollaborators()
    {
        const string json = @"{
  ""login"": ""octocat"",
  ""id"": 1234,
  ""url"": ""https://api.github.com/orgs/octocat"",
  ""repos_url"": ""https://api.github.com/orgs/octocat/repos"",
  ""events_url"": ""https://api.github.com/orgs/octocat/events"",
  ""hooks_url"": ""https://api.github.com/orgs/octocat/hooks"",
  ""issues_url"": ""https://api.github.com/orgs/octocat/issues"",
  ""members_url"": ""https://api.github.com/orgs/octocat/members{/member}"",
  ""public_members_url"": ""https://api.github.com/orgs/octocat/public_members{/member}"",
  ""avatar_url"": ""https://avatars.githubusercontent.com/u/1234?v=3"",
  ""description"": ""Test org."",
  ""name"": ""Octocat"",
  ""company"": null,
  ""blog"": ""http://octocat.abc"",
  ""location"": """",
  ""email"": """",
  ""public_repos"": 13,
  ""public_gists"": 0,
  ""followers"": 0,
  ""following"": 0,
  ""html_url"": ""https://github.com/octocat"",
  ""created_at"": ""2012-09-11T21:54:25Z"",
  ""updated_at"": ""2016-08-02T05:44:12Z"",
  ""type"": ""Organization"",
  ""total_private_repos"": 1,
  ""owned_private_repos"": 1,
  ""private_gists"": null,
  ""disk_usage"": null,
  ""collaborators"": null,
  ""billing_email"": null,
  ""plan"": {
    ""name"": ""organization"",
    ""space"": 976562499,
    ""private_repos"": 9999,
    ""filled_seats"": 45,
    ""seats"": 45
  }
}";
        var serializer = new SimpleJsonSerializer();

        var org = serializer.Deserialize<Organization>(json);

        Assert.Equal("octocat", org.Login);
        Assert.Equal(1234, org.Id);
    }
开发者ID:daveaglick,项目名称:octokit.net,代码行数:48,代码来源:OrganizationTests.cs


示例15: CanBeDeserialized

    public void CanBeDeserialized()
    {
        const string json = @"{
  ""total_count"": 40,
  ""incomplete_results"": false,
  ""items"": [
    {
      ""id"": 3081286,
      ""name"": ""Tetris"",
      ""full_name"": ""dtrupenn/Tetris"",
      ""owner"": {
        ""login"": ""dtrupenn"",
        ""id"": 872147,
        ""avatar_url"": ""https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"",
        ""gravatar_id"": """",
        ""url"": ""https://api.github.com/users/dtrupenn"",
        ""received_events_url"": ""https://api.github.com/users/dtrupenn/received_events"",
        ""type"": ""User""
      },
      ""private"": false,
      ""html_url"": ""https://github.com/dtrupenn/Tetris"",
      ""description"": ""A C implementation of Tetris using Pennsim through LC4"",
      ""fork"": false,
      ""url"": ""https://api.github.com/repos/dtrupenn/Tetris"",
      ""created_at"": ""2012-01-01T00:31:50Z"",
      ""updated_at"": ""2013-01-05T17:58:47Z"",
      ""pushed_at"": ""2012-01-01T00:37:02Z"",
      ""homepage"": """",
      ""size"": 524,
      ""stargazers_count"": 1,
      ""watchers_count"": 1,
      ""language"": ""Assembly"",
      ""forks_count"": 0,
      ""open_issues_count"": 0,
      ""master_branch"": ""master"",
      ""default_branch"": ""master"",
      ""score"": 10.309712
    }
  ]
}";
        var serializer = new SimpleJsonSerializer();

        var results = serializer.Deserialize<SearchRepositoryResult>(json);

        Assert.Equal(40, results.TotalCount);
        Assert.False(results.IncompleteResults);
    }
开发者ID:cloudRoutine,项目名称:octokit.net,代码行数:47,代码来源:SearchRepositoryResultTests.cs


示例16: CanDeserialize

        public void CanDeserialize()
        {
            const string json = @"{
              ""id"": 1,
              ""url"": ""https://api.github.com/repos/octocat/example/deployments/1/statuses/42"",
              ""state"": ""success"",
              ""creator"": {
                ""login"": ""octocat"",
                ""id"": 1,
                ""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
                ""gravatar_id"": ""somehexcode"",
                ""url"": ""https://api.github.com/users/octocat"",
                ""html_url"": ""https://github.com/octocat"",
                ""followers_url"": ""https://api.github.com/users/octocat/followers"",
                ""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
                ""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
                ""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
                ""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
                ""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
                ""repos_url"": ""https://api.github.com/users/octocat/repos"",
                ""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
                ""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
                ""type"": ""User"",
                ""site_admin"": false
              },
              ""payload"": { ""environment"":""production""},
              ""target_url"": ""https://gist.github.com/628b2736d379f"",
              ""created_at"": ""2012-07-20T01:19:13Z"",
              ""updated_at"": ""2012-07-20T01:19:13Z"",
              ""description"": ""Deploy request from hubot""
            }";

            var actual = new SimpleJsonSerializer().Deserialize<DeploymentStatus>(json);

            Assert.Equal(1, actual.Id);
            Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1/statuses/42", actual.Url);
            Assert.Equal(DeploymentState.Success, actual.State);
            Assert.Equal(1, actual.Payload.Count);
            Assert.Equal("production", actual.Payload["environment"]);
            Assert.Equal("https://gist.github.com/628b2736d379f", actual.TargetUrl);
            Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.CreatedAt);
            Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.UpdatedAt);
            Assert.Equal("Deploy request from hubot", actual.Description);
        }
开发者ID:cloudRoutine,项目名称:octokit.net,代码行数:44,代码来源:DeploymentStatusTests.cs


示例17: CanDeserialize

        public void CanDeserialize()
        {
            const string json = @"{
                    ""id"": 1,
                    ""sha"": ""topic-branch"",
                    ""url"": ""https://api.github.com/repos/octocat/example/deployments/1"",
                    ""creator"": {
                        ""login"": ""octocat"",
                        ""id"": 1,
                        ""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
                        ""gravatar_id"": ""somehexcode"",
                        ""url"": ""https://api.github.com/users/octocat"",
                        ""html_url"": ""https://github.com/octocat"",
                        ""followers_url"": ""https://api.github.com/users/octocat/followers"",
                        ""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
                        ""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
                        ""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
                        ""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
                        ""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
                        ""repos_url"": ""https://api.github.com/users/octocat/repos"",
                        ""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
                        ""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
                        ""type"": ""User"",
                        ""site_admin"": false
                    },
                    ""payload"": { ""environment"":""production""},
                    ""created_at"": ""2012-07-20T01:19:13Z"",
                    ""updated_at"": ""2012-07-20T01:19:13Z"",
                    ""description"": ""Deploy request from hubot"",
                    ""statuses_url"": ""https://api.github.com/repos/octocat/example/deployments/1/statuses""
                }";

            var actual = new SimpleJsonSerializer().Deserialize<Deployment>(json);
            
            Assert.Equal(1, actual.Id);
            Assert.Equal("topic-branch", actual.Sha);
            Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1", actual.Url);
            Assert.Equal(new ReadOnlyDictionary<string, string>(new Dictionary<string, string> { { "environment", "production" } }), actual.Payload);
            Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.CreatedAt);
            Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.UpdatedAt);
            Assert.Equal("Deploy request from hubot", actual.Description);
            Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1/statuses", actual.StatusesUrl);
        }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:43,代码来源:DeploymentTests.cs


示例18: CanBeDeserialized

        public void CanBeDeserialized()
        {
            const string json = @"{
   ""message"": ""Validation Failed"",
   ""errors"": [
     {
       ""resource"": ""Issue"",
       ""field"": ""title"",
       ""code"": ""missing_field""
     }
   ]
 }";
            var serializer = new SimpleJsonSerializer();

            var apiError = serializer.Deserialize<ApiError>(json);

            Assert.Equal("Validation Failed", apiError.Message);
            Assert.Equal(1, apiError.Errors.Count);
            Assert.Equal("Issue", apiError.Errors[0].Resource);
            Assert.Equal("title", apiError.Errors[0].Field);
            Assert.Equal("missing_field", apiError.Errors[0].Code);
        }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:22,代码来源:ApiErrorTests.cs


示例19: DeserializesInheritedProperties

            public void DeserializesInheritedProperties()
            {
                const string json = "{\"sha\":\"commit-sha\",\"url\":\"commit-url\",\"message\":\"commit-message\"}";

                var result = new SimpleJsonSerializer().Deserialize<Commit>(json);

                Assert.Equal("commit-sha", result.Sha);
                Assert.Equal("commit-url", result.Url);
                Assert.Equal("commit-message", result.Message);
            }
开发者ID:rahulvramesh,项目名称:octokit.net,代码行数:10,代码来源:SimpleJsonSerializerTests.cs


示例20: DefaultsMissingParameters

            public void DefaultsMissingParameters()
            {
                const string json = @"{""private"":true}";

                var sample = new SimpleJsonSerializer().Deserialize<Sample>(json);

                Assert.Equal(0, sample.Id);
                Assert.Equal(null, sample.FirstName);
                Assert.False(sample.IsSomething);
                Assert.True(sample.Private);
            }
开发者ID:daveaglick,项目名称:octokit.net,代码行数:11,代码来源:SimpleJsonSerializerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SimpleOrientation类代码示例发布时间:2022-05-24
下一篇:
C# SimpleFillSymbolClass类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap