本文介绍了提取API从响应中获取原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用React-Native请求一些数据,这是我的代码:
I use React-Native request some data, here is my code:
fetch('raw.githubusercontent/facebook/react-native/master/docs/MoviesExample.json') .then((response)=>{ return response.json() }) .then((responseJSON)=>{ callback(responseJSON) }) .catch((error)=>{ console.error(error); }) .done()我看到response是Response对象,而json功能代码是return this.text().then(JSON.parse),我很困惑JSON.parse的参数是什么?那是response原始值吗?我怎么能得到它?
I see the response is a Response object, and the json function code is return this.text().then(JSON.parse), I'm confused that what is the parameter of theJSON.parse? Is that the response raw value? How can I get it?
推荐答案以下是您要执行的操作.就我而言,我想手动解析JSON,因为内置JSON解析器不正确地解析了某个字符(\ u001e).
Here's how you'd do what you want. In my case I wanted to manually parse the JSON because a certain character (\u001e) is improperly parsed by the in-built JSON parser.
更改自:
fetch(url) .then(response => response.json()) .then((data) => { data....收件人:
fetch(url) .then(response => response.text()) .then((dataStr) => { let data = JSON.parse(dataStr); data...更多推荐
提取API从响应中获取原始值
发布评论