我正在开发一个flutter应用程序,该应用程序使用带有阿拉伯字符的其余API,阿拉伯字符显示不佳。
http.get请求的代码:
Future<Null> fetchCustomers() {
_isLoading = true;
notifyListeners();
return http.get('http://10.0.3.2:8000/transfers/', headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.acceptCharsetHeader:'utf-8',
}).then<Null>((http.Response response) {
final List<Customer> fetchedCustomerList = [];
var customerListData = json.decode(response.body);
print(customerListData);
print('here');
final customerData =
(customerListData as List).map((i) => new Customer.fromJson(i));
print(customerData);
print('before');
if (customerListData == null) {
_isLoading = false;
notifyListeners();
return;
}
customerListData.forEach((customerData) {
final Customer customer = Customer(
id: customerData['id'],
name: customerData['name']
mobile: customerData['mobile'],
address: customerData['address'],
);
fetchedCustomerList.add(customer);
});
_customers = fetchedCustomerList;
print(_customers);
print("after");
_isLoading = false;
notifyListeners();
_selCustomerId = null;
}).catchError((error) {
_isLoading = false;
notifyListeners();
return;
});
}
答案 0 :(得分:4)
只需添加
(json.decode(utf8.decode(response.bodyBytes)))
代替json.decode(response.body)
这会将您的json解码为阿拉伯语
答案 1 :(得分:0)