Skip to content

Commit

Permalink
update json error
Browse files Browse the repository at this point in the history
  • Loading branch information
a1henu committed May 1, 2024
1 parent b096083 commit 3976982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions citation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ std::string Article::toString() const {
if (data.is_null()) {
std::exit(1);
}
if (info["title"].is_string() &&
if (info.contains("title") &&
info.contains("author") &&
info.contains("journal") &&
info.contains("year") &&
info.contains("volume") &&
info.contains("issue") &&
info["title"].is_string() &&
info["author"].is_string() &&
info["journal"].is_string() &&
info["year"].is_number() &&
Expand Down Expand Up @@ -77,7 +83,11 @@ std::string Book::toString() const {
if (data.is_null()) {
std::exit(1);
}
if (info["author"].is_string() &&
if (info.contains("author") &&
info.contains("title") &&
info.contains("publisher") &&
info.contains("year") &&
info["author"].is_string() &&
info["title"].is_string() &&
info["publisher"].is_string() &&
info["year"].is_string())
Expand Down Expand Up @@ -112,7 +122,7 @@ std::string WebPage::toString() const {
if (data.is_null()) {
std::exit(1);
}
if (info["title"].is_string()) {
if (info.contains("title") && info["title"].is_string()) {
std::string title = info["title"].get<std::string>();
return std::string("[" + id + "] webpage: " + title + ". Available at " + url);
} else {
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::unordered_map<std::string, CitationPtr> loadCitations(const std::string& fi
nlohmann::json citationJson;

try {
file >> citationJson;
citationJson = nlohmann::json::parse(file);
} catch (...) {
std::exit(1);
}
Expand Down

0 comments on commit 3976982

Please sign in to comment.