0

I have been trying to get a JSON response form API call which return a localised strings. Works well in Postman with same setup as http calls. but when make an API call from application it returns weird string - please check below.

I tried passing header for supporting language but does not work

JSON response in Postman - "text": "Número OMI-IMO", JSON response through application - "text":"Número OMI-IMO"

http.Response response = await http.get(
  login,
  headers: {'Consumer-Key': consumerKey, 'Accept-Language': '*'},
);

I have also tried setting my device default language to respective localized language in this case Spanish, local strings used int he application works fine.

Tried binding the string "text": "Número OMI-IMO", from JSON file works well.

The response re not working only with API response strings, its same with other language like Frensh, Portuguese.

Been trying different solution but nothing work this problem exist on both Android and iOS.

enter image description here

3
  • Does this answer your question? Postman utf-8 encoding issue when charset=utf-8 is not provided by server Commented Nov 30, 2020 at 4:21
  • Adding header to api as 'Accept': 'application/json;charset=UTF-8' worked for me, thank you for the insight. Commented Nov 30, 2020 at 4:27
  • body = utf8.decode(response.bodyBytes); if response has utf8 headers, use line above Commented Nov 30, 2020 at 11:31

1 Answer 1

0

Import this dart lib on the head of the file

import 'dart:convert' as convert

then you do

String jsonString = convert.utf8.decode(response.bodyBytes);

Now you will have a proper formatted and decoded JSON

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.