I am building a book app with Flutter for Android and iOS. I am using Google Books API to retrieve book data, but I have noticed something strange which I dont understand. If we look at the book data displayed in chrome browser (
The code that I'm using to get the API data can be seen below:
Response result = await http.get(Uri.parse(url), headers: {'content-type': 'application/json; charset=utf-8'});
if (result.statusCode == 200) {
final jsonResponse = jsonDecode(utf8.decode(result.bodyBytes));
if (jsonResponse["totalItems"] == 0) {
return List.empty();
}
//this prints out the content in above image
print(result.body.toString());
final booksMap = jsonResponse['items'];
List<dynamic> books = booksMap.map((i) => Book.fromJson(i)).toList();
return books;
CodePudding user response:
It seems that https://www.googleapis.com/books/v1/volumes/b3GuDwAAQBAJ gives different data than your usual search query (eg. https://www.googleapis.com/books/v1/volumes?q=isbn:9780143123231). I do not know the reason why.
CodePudding user response:
You can see the API response in raw form due to which unicode are present
but when you get api response you can parse into json, By parsing json that unicodes are removed and data is in proper format
if you use json Formatter
extension in chrome you can see that the data in chrome in Json form and the response from api when you are hitting api by code are same.
in the application code , you set headers: {'content-type': 'application/json;
thats why u received Json data code. and its not problem because you will use this data into your application,
you can see more content types here
Blockquote