Issue
JSON response String containing an apostrophe
This is the key and value coming from the server.
"name": "men’s basketball wear with free product",
When I'm converting this JSON into pojo response Future<Product> returning me this when I print the string in the log.
PRODUCT NAME
menĂ¢s basketball wear with free product
I have tried this solution but nothing is happening
replaceAll("'", "\'").replaceAll('"', "\'")
replaceAll('"', '\\"')
I have tried in response class
Product.fromJsonMap(Map<String, dynamic> map):
pid = map["pid"],
aid = map["aid"],
name = map["name"].replaceAll("'", "\'");
My HTTP request
http.Response res = await http.get(url);
Solution
As @Richard Heap answer
http.Response response = await http.get('SOME URL',headers: {'Content- Type':'application/json'});
List<dynamic> responseJson = json.decode(utf8.decode(response.bodyBytes));
Answered By - Farhana Naaz Ansari

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.