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


C# SimpleJsonSerializer类代码示例

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


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


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