【发布时间】:2018-05-29 12:11:03
【问题描述】:
以下是我读取已下载并存储在“TemporaryDirectoryPath”中的 JSON 文件的代码。
var fileName = getFileNameFromUrl(url);
RNFS.downloadFile({
fromUrl: url,
toFile: `${RNFS.TemporaryDirectoryPath}/`+fileName
}).promise.then(r => {
var content = RNFS.readFile(`${RNFS.TemporaryDirectoryPath}/`+fileName, 'utf8');
console.log(content);
});
我得到一个“Promise”类型的对象,如下所示
Promise {_40: 0, _65: 0, _55: null, _72: null}
_40: 0
_55: "{"show_explanation":1,"answer_result":2, //More json content will be here}"
_65: 1
_72: null
如何从该 Promise 对象中读取内容?
【问题讨论】:
-
这个问题可能是重复的:stackoverflow.com/questions/49770756/…
-
并且由于他们两个都没有得到正确的回答,所以我失败了一个更具体的方法,有多种方法展示了 react-native-fs 的状态:stackoverflow.com/questions/59028704/…
标签: react-native react-native-fs