diff --git a/pixivmodels.cpp b/pixivmodels.cpp index c21e817..e609179 100644 --- a/pixivmodels.cpp +++ b/pixivmodels.cpp @@ -53,15 +53,14 @@ void from_json(const nlohmann::json& j, User& user) { user.profile_pictures.thumbnails.push_back(profile_img.at("main").get()); user.profile_pictures.original = get_original_profile_picture(user.profile_pictures.thumbnails.back()); - std::string user_webpage = j.at("user_webpage").get(); - if (!user_webpage.empty()) { - user.links.push_back({"Webpage", std::move(user_webpage)}); + if (j.contains("user_webpage")) { + std::string user_webpage = j.at("user_webpage").get(); + if (!user_webpage.empty()) { + user.links.push_back({"Webpage", std::move(user_webpage)}); + } } auto add_social_as_needed = [&](const char* key, const char* public_name) { - nlohmann::json social = j.at("social"); - if (!social.is_object()) { - return; - } + nlohmann::json social = j["social"]; if (!social.contains(key)) { return; } @@ -69,12 +68,14 @@ void from_json(const nlohmann::json& j, User& user) { std::string url = social[key].at("url").get(); user.links.push_back({public_name, std::move(url)}); }; - add_social_as_needed("twitter", "Twitter"); - add_social_as_needed("instagram", "Instagram"); - add_social_as_needed("tumblr", "Tumblr"); - add_social_as_needed("facebook", "Facebook"); - add_social_as_needed("circlems", "Circle.ms"); - add_social_as_needed("pawoo", "Pawoo"); + if (j.contains("social") && j["social"].is_object()) { + add_social_as_needed("twitter", "Twitter"); + add_social_as_needed("instagram", "Instagram"); + add_social_as_needed("tumblr", "Tumblr"); + add_social_as_needed("facebook", "Facebook"); + add_social_as_needed("circlems", "Circle.ms"); + add_social_as_needed("pawoo", "Pawoo"); + } } static std::regex resolution_path_regex("/c/(\\d+x\\d+)(.+)");