问题
I'm using async/await
with React Native.
My result from response.json()
is:
{ _45: 0, _81: 0, _65: null, _54: null }
For whatever reason, the actual response I want is located in _65 and I have no idea what these random keys are.
It seems that it is related to the fact that .json()
returns a Promise.
componentDidMount() {
this.getData().then(data => this.setState({ data }))
}
async getData() {
try {
let response = await fetch(myUrl)
let json = await response.json()
return json
} catch(err) {
Alert.alert(null, err)
}
}
render() {
const { data } = this.state
...
回答1:
The answer is: this.getData().then(data => this.setState({ data }))
来源:https://stackoverflow.com/questions/36285564/why-does-fetch-return-a-weird-hash-of-integers-part-2