【问题标题】:How would I parse JSON with use of API in React-Native?如何在 React-Native 中使用 API 解析 JSON?
【发布时间】:2017-11-29 11:24:25
【问题描述】:

我正在尝试解析 4、4c 的离场,但它不起作用。

【问题讨论】:

  • 什么是“4、4c 出发”? “它不起作用”是什么意思?你想让它做什么?此外,我在上面的代码中看到任何尝试解析的零证据。
  • return fetch('transportapi.com/v3/uk/bus/stop/6090282/…) .then((response) => response.json()) .then((responseJson) => { alert( this.setState({data : responseJson.出发}));
  • 我觉得这个是在解析...
  • 点击Api键可以看到deaprture :{ "4" :[...], "4c":[...] }
  • 那个获取响应没有解析,它把数据设置为状态。该 API 密钥中也没有 4 或 4c。只有4A

标签: json react-native react-native-android expo


【解决方案1】:

this.setState 不会返回导致您未定义的结果。

试试这个

this.setState({data : responseJson.departures});
alert( JSON.stringify(this.state.data));

【讨论】:

  • {this.state.data} 就是我想的你想要的。
  • @DHC {JSON.stringify(this.state.data, null, 2)}
猜你喜欢
  • 1970-01-01
  • 2017-10-21
  • 2017-02-12
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多