本文整理汇总了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);
}
示例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);
}
示例3: PlainScript
public PlainScript(IAsset asset, Bundle bundle, IAmdConfiguration modules)
: base(asset, bundle)
{
this.modules = modules;
jsonSerializer = new SimpleJsonSerializer();
asset.AddAssetTransformer(this);
}
示例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);
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}