Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
解决Null的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed May 18, 2019
1 parent 26467c6 commit 7477e26
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 64 deletions.
2 changes: 1 addition & 1 deletion PixivFSUWP/Data/BookmarkIllustsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c
.UserBookmarksIllust(userID, getparam("restrict"),
getparam("filter"), getparam("max_bookmark_id"));
}
nexturl = bookmarkres["next_url"].GetString();
nexturl = bookmarkres["next_url"].TryGetString();
foreach (var recillust in bookmarkres["illusts"].GetArray())
{
if (_emergencyStop)
Expand Down
2 changes: 1 addition & 1 deletion PixivFSUWP/Data/CommentsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c
.PixivAppAPI(OverAll.GlobalBaseAPI)
.IllustComments(illustid, getparam("offset"), bool.Parse(getparam("include_total_comments")));
}
nexturl = commentres["next_url"].GetString();
nexturl = commentres["next_url"].TryGetString();
foreach (var recillust in commentres["comments"].GetArray())
{
if (_emergencyStop)
Expand Down
14 changes: 7 additions & 7 deletions PixivFSUWP/Data/CurrentUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public class CurrentUser
public static CurrentUser FromJsonValue(JsonObject Source)
{
CurrentUser toret = new CurrentUser();
toret.ID = Convert.ToInt32(Source["id"].GetString());
toret.Username = Source["name"].GetString();
toret.UserAccount = Source["account"].GetString();
toret.Email = Source["mail_address"].GetString();
toret.ID = Convert.ToInt32(Source["id"].TryGetString());
toret.Username = Source["name"].TryGetString();
toret.UserAccount = Source["account"].TryGetString();
toret.Email = Source["mail_address"].TryGetString();
toret.IsMailAuthorized = Source["is_mail_authorized"].GetBoolean();
toret.IsPremium = Source["is_premium"].GetBoolean();
toret.Avatar16 = Source["profile_image_urls"].GetObject()["px_16x16"].GetString();
toret.Avatar50 = Source["profile_image_urls"].GetObject()["px_50x50"].GetString();
toret.Avatar170 = Source["profile_image_urls"].GetObject()["px_170x170"].GetString();
toret.Avatar16 = Source["profile_image_urls"].GetObject()["px_16x16"].TryGetString();
toret.Avatar50 = Source["profile_image_urls"].GetObject()["px_50x50"].TryGetString();
toret.Avatar170 = Source["profile_image_urls"].GetObject()["px_170x170"].TryGetString();
return toret;
}
}
Expand Down
2 changes: 1 addition & 1 deletion PixivFSUWP/Data/FollowingIllustsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c
.PixivAppAPI(OverAll.GlobalBaseAPI)
.IllustFollow(getparam("restrict"), getparam("offset"));
}
nexturl = followingres["next_url"].GetString();
nexturl = followingres["next_url"].TryGetString();
foreach (var recillust in followingres["illusts"].GetArray())
{
if (_emergencyStop)
Expand Down
10 changes: 5 additions & 5 deletions PixivFSUWP/Data/IllustCommentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class IllustCommentItem
public static IllustCommentItem FromJsonValue(JsonObject Source)
{
IllustCommentItem toret = new IllustCommentItem();
toret.Comment = Source["comment"].GetString();
toret.DateTime = Source["date"].GetString();
toret.UserName = Source["user"].GetObject()["name"].GetString();
toret.UserAccount = Source["user"].GetObject()["account"].GetString();
toret.AvatarUrl = Source["user"].GetObject()["profile_image_urls"].GetObject()["medium"].GetString();
toret.Comment = Source["comment"].TryGetString();
toret.DateTime = Source["date"].TryGetString();
toret.UserName = Source["user"].GetObject()["name"].TryGetString();
toret.UserAccount = Source["user"].GetObject()["account"].TryGetString();
toret.AvatarUrl = Source["user"].GetObject()["profile_image_urls"].GetObject()["medium"].TryGetString();
return toret;
}
}
Expand Down
24 changes: 12 additions & 12 deletions PixivFSUWP/Data/IllustDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ public static IllustDetail FromJsonValue(JsonObject Source)
{
IllustDetail toret = new IllustDetail();
toret.IllustID = (int)Source["illust"].GetObject()["id"].GetNumber();
toret.Title = Source["illust"].GetObject()["title"].GetString();
toret.Type = Source["illust"].GetObject()["type"].GetString();
toret.Caption = Source["illust"].GetObject()["caption"].GetString();
toret.Title = Source["illust"].GetObject()["title"].TryGetString();
toret.Type = Source["illust"].GetObject()["type"].TryGetString();
toret.Caption = Source["illust"].GetObject()["caption"].TryGetString();
toret.AuthorID = (int)Source["illust"].GetObject()["user"].GetObject()["id"].GetNumber();
toret.Author = Source["illust"].GetObject()["user"].GetObject()["name"].GetString();
toret.AuthorAccount = Source["illust"].GetObject()["user"].GetObject()["account"].GetString();
toret.AuthorAvatarUrl = Source["illust"].GetObject()["user"].GetObject()["profile_image_urls"].GetObject()["medium"].GetString();
toret.Author = Source["illust"].GetObject()["user"].GetObject()["name"].TryGetString();
toret.AuthorAccount = Source["illust"].GetObject()["user"].GetObject()["account"].TryGetString();
toret.AuthorAvatarUrl = Source["illust"].GetObject()["user"].GetObject()["profile_image_urls"].GetObject()["medium"].TryGetString();
toret.IsUserFollowed = Source["illust"].GetObject()["user"].GetObject()["is_followed"].GetBoolean();
var tags = Source["illust"].GetObject()["tags"].GetArray();
toret.Tags = new List<string>();
foreach (var tag in tags)
toret.Tags.Add(tag.GetObject()["name"].GetString());
toret.Tags.Add(tag.GetObject()["name"].TryGetString());
var tools = Source["illust"].GetObject()["tools"].GetArray();
toret.Tools = new List<string>();
foreach (var tool in tools)
toret.Tools.Add(tool.GetString());
toret.CreateDate = Source["illust"].GetObject()["create_date"].GetString();
toret.MediumUrl = Source["illust"].GetObject()["image_urls"].GetObject()["square_medium"].GetString();
toret.Tools.Add(tool.TryGetString());
toret.CreateDate = Source["illust"].GetObject()["create_date"].TryGetString();
toret.MediumUrl = Source["illust"].GetObject()["image_urls"].GetObject()["square_medium"].TryGetString();
var pgCount = (int)Source["illust"].GetObject()["page_count"].GetNumber();
toret.OriginalUrls = new List<string>();
if (pgCount == 1) toret.OriginalUrls.Add(Source["illust"].GetObject()["meta_single_page"].GetObject()["original_image_url"].GetString());
if (pgCount == 1) toret.OriginalUrls.Add(Source["illust"].GetObject()["meta_single_page"].GetObject()["original_image_url"].TryGetString());
else
{
var pages = Source["illust"].GetObject()["meta_pages"].GetArray();
foreach (var page in pages)
toret.OriginalUrls.Add(page.GetObject()["image_urls"].GetObject()["original"].GetString());
toret.OriginalUrls.Add(page.GetObject()["image_urls"].GetObject()["original"].TryGetString());
}
toret.Width = (int)Source["illust"].GetObject()["width"].GetNumber();
toret.Height = (int)Source["illust"].GetObject()["height"].GetNumber();
Expand Down
9 changes: 9 additions & 0 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using AdaptiveCards;
using Windows.UI.Shell;
using PixivCS;
using Windows.Data.Json;

namespace PixivFSUWP.Data
{
Expand Down Expand Up @@ -146,5 +147,13 @@ public static async Task GenerateActivityAsync(string DisplayText, AdaptiveCard
_currentActivity?.Dispose();
_currentActivity = userActivity.CreateSession();
}

//扩展方法,用于检测值为null的情况
public static string TryGetString(this IJsonValue source)
{
if (source.ValueType == JsonValueType.Null)
return null;
return source.GetString();
}
}
}
2 changes: 1 addition & 1 deletion PixivFSUWP/Data/RecommendIllustsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c
IncludeRankingIllusts: bool.Parse(getparam("include_ranking_illusts")),
IncludePrivacyPolicy: getparam("include_privacy_policy"));
}
nexturl = recommendres["next_url"].GetString();
nexturl = recommendres["next_url"].TryGetString();
foreach (var recillust in recommendres["illusts"].GetArray())
{
if (_emergencyStop)
Expand Down
66 changes: 33 additions & 33 deletions PixivFSUWP/Data/UserDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ public static UserDetail FromJsomValue(JsonObject Source)
UserDetail toret = new UserDetail();
var user = Source["user"].GetObject();
toret.ID = (int)user["id"].GetNumber();
toret.Name = user["name"].GetString();
toret.Account = user["account"].GetString();
toret.AvatarUrl = user["profile_image_urls"].GetObject()["medium"].GetString();
toret.Comment = user["comment"].GetString();
toret.Name = user["name"].TryGetString();
toret.Account = user["account"].TryGetString();
toret.AvatarUrl = user["profile_image_urls"].GetObject()["medium"].TryGetString();
toret.Comment = user["comment"].TryGetString();
toret.IsFollowed = user["is_followed"].GetBoolean();
var profile = Source["profile"].GetObject();
toret.WebPage = profile["webpage"].GetString();
toret.Gender = profile["gender"].GetString();
toret.Birth = profile["birth"].GetString();
toret.BirthDay = profile["birth_day"].GetString();
toret.WebPage = profile["webpage"].TryGetString();
toret.Gender = profile["gender"].TryGetString();
toret.Birth = profile["birth"].TryGetString();
toret.BirthDay = profile["birth_day"].TryGetString();
toret.BirthYear = (int)profile["birth_year"].GetNumber();
toret.Region = profile["region"].GetString();
toret.Region = profile["region"].TryGetString();
toret.AddressID = (int)profile["address_id"].GetNumber();
toret.CountryCode = profile["country_code"].GetString();
toret.Job = profile["job"].GetString();
toret.CountryCode = profile["country_code"].TryGetString();
toret.Job = profile["job"].TryGetString();
toret.JobID = (int)profile["job_id"].GetNumber();
toret.TotalFollowUsers = (int)profile["total_follow_users"].GetNumber();
toret.TotalMyPixivUsers = (int)profile["total_mypixiv_users"].GetNumber();
Expand All @@ -88,33 +88,33 @@ public static UserDetail FromJsomValue(JsonObject Source)
toret.TotalIllustBookmarksPublic = (int)profile["total_illust_bookmarks_public"].GetNumber();
toret.TotalIllustSeries = (int)profile["total_illust_series"].GetNumber();
toret.TotalNovelSeries = (int)profile["total_novel_series"].GetNumber();
toret.BackgroundImage = profile["background_image_url"].GetString();
toret.TwitterAccount = profile["twitter_account"].GetString();
toret.TwitterUrl = profile["twitter_url"].GetString();
toret.PawooUrl = profile["pawoo_url"].GetString();
toret.BackgroundImage = profile["background_image_url"].TryGetString();
toret.TwitterAccount = profile["twitter_account"].TryGetString();
toret.TwitterUrl = profile["twitter_url"].TryGetString();
toret.PawooUrl = profile["pawoo_url"].TryGetString();
toret.IsPremium = profile["is_premium"].GetBoolean();
toret.IsUsingCustomProfileImage = profile["is_using_custom_profile_image"].GetBoolean();
var profile_publicity = Source["profile_publicity"].GetObject();
toret.GenderPublicity = profile_publicity["gender"].GetString();
toret.RegionPublicity = profile_publicity["region"].GetString();
toret.BirthDayPublicity = profile_publicity["birth_day"].GetString();
toret.BirthYearPublicity = profile_publicity["birth_year"].GetString();
toret.JobPublicity = profile_publicity["job"].GetString();
toret.GenderPublicity = profile_publicity["gender"].TryGetString();
toret.RegionPublicity = profile_publicity["region"].TryGetString();
toret.BirthDayPublicity = profile_publicity["birth_day"].TryGetString();
toret.BirthYearPublicity = profile_publicity["birth_year"].TryGetString();
toret.JobPublicity = profile_publicity["job"].TryGetString();
toret.Pawoo = profile_publicity["pawoo"].GetBoolean();
var workspace = Source["workspace"].GetObject();
toret.PC = workspace["pc"].GetString();
toret.Monitor = workspace["monitor"].GetString();
toret.Tool = workspace["tool"].GetString();
toret.Scanner = workspace["scanner"].GetString();
toret.Tablet = workspace["tablet"].GetString();
toret.Mouse = workspace["mouse"].GetString();
toret.Printer = workspace["printer"].GetString();
toret.Desktop = workspace["desktop"].GetString();
toret.Music = workspace["music"].GetString();
toret.Desk = workspace["desk"].GetString();
toret.Chair = workspace["chair"].GetString();
toret.WorkspaceComment = workspace["comment"].GetString();
toret.WorkspaceImageUrl = workspace["workspace_image_url"].GetString();
toret.PC = workspace["pc"].TryGetString();
toret.Monitor = workspace["monitor"].TryGetString();
toret.Tool = workspace["tool"].TryGetString();
toret.Scanner = workspace["scanner"].TryGetString();
toret.Tablet = workspace["tablet"].TryGetString();
toret.Mouse = workspace["mouse"].TryGetString();
toret.Printer = workspace["printer"].TryGetString();
toret.Desktop = workspace["desktop"].TryGetString();
toret.Music = workspace["music"].TryGetString();
toret.Desk = workspace["desk"].TryGetString();
toret.Chair = workspace["chair"].TryGetString();
toret.WorkspaceComment = workspace["comment"].TryGetString();
toret.WorkspaceImageUrl = workspace["workspace_image_url"].TryGetString();
return toret;
}
}
Expand Down
6 changes: 3 additions & 3 deletions PixivFSUWP/Data/WaterfallItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static WaterfallItem FromJsonValue(JsonObject Source)
var toret = new WaterfallItem();
var test = Source["id"];
toret.Id = (int)Source["id"].GetNumber();
toret.Title = Source["title"].GetString();
toret.Author = Source["user"].GetObject()["name"].GetString();
toret.ImageUri = Source["image_urls"].GetObject()["medium"].GetString();
toret.Title = Source["title"].TryGetString();
toret.Author = Source["user"].GetObject()["name"].TryGetString();
toret.ImageUri = Source["image_urls"].GetObject()["medium"].TryGetString();
toret.Stars = (int)Source["total_bookmarks"].GetNumber();
toret.Pages = (int)Source["page_count"].GetNumber();
toret.IsBookmarked = Source["is_bookmarked"].GetBoolean();
Expand Down

0 comments on commit 7477e26

Please sign in to comment.