我正在使用react native 0.48.3并从提取请求中获取响应,我看不到任何编码问题可以自行解决编码问题,因为响应的内容类型为:application / json; charset = iso-8859-1 。现在,我将我的react native应用程序升级到0.59.8,尽管它是相同的代码,但我不知道为什么fetch不再解决编码问题。我刚刚升级了我的应用程序。你有什么主意吗 ?这是我的提取代码:
export const setDocumentListDataAsync = (k, action, server) => {
return () => {
fetch(defineUrlForDocumentList(action, server), {
credentials: 'include',
headers:{
contentType: "application/json; charset=utf-8",
}
})
.then(
(response) => {
var contentType = response.headers.get('content-type')
console.warn(contentType)
return response
}
).then((response) => {
return response.json()
}).catch((err) => {
console.log(err)
})
}
}
我认为您必须这样做:
export const setDocumentListDataAsync = (k, action, server) => {
return () => {
fetch(defineUrlForDocumentList(action, server), {
credentials: 'include',
headers:{
contentType: "application/json; charset=utf-8",
}
})
.then(
(response) => {
var contentType = response.headers.get('content-type')
console.warn(contentType)
return response.json()
}
).then((myJson) => {
console.log(JSON.stringify(myJson));
}).catch((err) => {
console.log(err)
})
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句