Fetch Encoding issue - React Native

核能气质少年 提交于 2019-12-11 07:33:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!