问题
While parsing fetch response, it can't able to parse special characters in response.
Please find alert response where special characters are breaking.
While hitting request in postman, this is the response message.
Here is my fetch request
fetch(restUrl, {
method: "POST",
headers: {
'x-nanobnk-apikey': urls.APIKey,
// 'x-nanobnk-auth': this.token,
'Accept-Language': this.state.stLang,
'Accept': '*/*',
'charset': 'utf-8',
'Content-Type': 'application/json',
},
body: JSON.stringify(objReq)
})
)
// .then(ApiUtils.checkStatus)
.then(response => {
if (response.status >= 200 && response.status < 300) {
return response.text()
}
else {
return response.json()
}
}
)
.then(responseJson => {
let obj = responseJson;
if (responseJson != null && responseJson != undefined) {
if (obj.hasOwnProperty('error') || obj.hasOwnProperty('errorType')) {
// failure scenario
console.log(responseJson + "from failure scenario");
this.setState({ btnDisableBool: false });
alert(obj.message);
}
else {
// Success response
}
}
else {
this.setState({ btnDisableBool: false });
alert(i18n.t('unable'));
}
})
as you can see I'm even passing 'Charset'-'utf-8' header parameter.
Please let me know how to resolve this.
来源:https://stackoverflow.com/questions/51168982/fetch-encoding-issue-react-native