From 1dc3a388d4549c3e7065df9b0937b652b444586c Mon Sep 17 00:00:00 2001 From: h7x4abk3g Date: Wed, 24 Jun 2020 01:52:11 +0200 Subject: [PATCH] Fixed JishoAttribution bool value parsing --- lib/src/objects.dart | 10 +++++----- lib/src/unofficial_jisho_api_base.dart | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/objects.dart b/lib/src/objects.dart index dc6c9cf..2ea255a 100644 --- a/lib/src/objects.dart +++ b/lib/src/objects.dart @@ -364,7 +364,7 @@ class JishoWordSense { class JishoAttribution { bool jmdict; bool jmnedict; - bool dbpedia; + bool dbpedia; //This variable might be returned as a link (String). Not sure about the above JishoAttribution({ this.jmdict, @@ -373,10 +373,10 @@ class JishoAttribution { }); factory JishoAttribution.fromJson(Map json){ - return JishoAttribution( //TODO: This is broken. Find the potential values of a json result and fix - jmdict: (json['jmdict'] == 'true'), - jmnedict: (json['jmnedict'] == 'true'), - dbpedia: (json['dbpedia'] == 'true') + return JishoAttribution( + jmdict: (json['jmdict'].toString() == 'true'), + jmnedict: (json['jmnedict'].toString() == 'true'), + dbpedia: (json['dbpedia'].toString() == 'true') ); } diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart index d7c36fb..635d983 100644 --- a/lib/src/unofficial_jisho_api_base.dart +++ b/lib/src/unofficial_jisho_api_base.dart @@ -18,10 +18,9 @@ class JishoApi { /// @returns {Object} The response data from the official Jisho.org API. Its format is somewhat /// complex and is not documented, so put on your trial-and-error hat. /// @async - Future> searchForPhrase(String phrase) async { + Future searchForPhrase(String phrase) async { final uri = uriForPhraseSearch(phrase); - final jsonData = await http.get(uri).then((response) => JishoAPIResult.fromJson(jsonDecode(response.body))); - return jsonData.data; + return await http.get(uri).then((response) => JishoAPIResult.fromJson(jsonDecode(response.body))); } /// Scrape Jisho.org for information about a kanji character.