Reputation: 157
I've tried to insert my html text to display in my Flutter app. I've got some warning, but the result was good.
My Code:
final response = await http.get(
Uri.parse(BaseUrl.apiBaseUrl + 'myapi'),
headers: { HttpHeaders.authorizationHeader: "Bearer " + token });
final result = json.decode(response.body);
How I fix this warning?
I/flutter ( 8104): FormatException: Unexpected character (at character
- I/flutter ( 8104): I/flutter ( 8104): ^ I/flutter ( 8104): FormatException: Unexpected character (at character 1) I/flutter ( 8104): I/flutter ( 8104): ^
Output:
Upvotes: 1
Views: 6167
Reputation: 1943
My guess based on the info you've given is that response.body
is not valid JSON. The warning thrown does match with it. Can you log out response.body
before calling json.decode()
on it and validate this theory?
Also, you're saying that you are trying to insert HTML - why is it being decoded from JSON? Maybe you can skip the decode altogether when you're only interested in the raw output of the http.get()
query.
Upvotes: 1
Reputation: 1200
The problem is on final result = json.decode(response.body);
In your response body, you are either getting a null or a non JSON format. That's why when your code is decoding it into JSON there is an exception.
Upvotes: 3