【问题标题】:Can't recover all values from Json page using Axios and React Native无法使用 Axios 和 React Native 从 Json 页面恢复所有值
【发布时间】:2018-04-03 15:26:33
【问题描述】:

我从网址“https://api.myjson.com/bins/1f1pxv”得到下面的结果

{
  "categoria": "Graduação - Semipresenciais",
  "cursos": [
    {
      "name": "Engenharia de Computação",
      "tarefas": "1"
    },
    {
      "name": "Engenharia de Computação",
      "tarefas": "2"
    },
    {
      "name": "Psicologia",
      "tarefas": "4"
    }
  ]
}

我使用 React Native 和 Axios 来获取值

buscaCursosJson = () => {      
    axios.get("https://api.myjson.com/bins/1f1pxv").then(response => {
      alert('x2: '+response.data.cursos.name)
      alert('x1: '+response.data.categoria)
    })

};

警报“x1”正确显示结果“Graduação - Semipresenciais”,但“x2”警报结果显示“未定义”。

我该如何解决这个问题?

【问题讨论】:

    标签: react-native axios


    【解决方案1】:

    我找到解决问题的方法,我使用地图功能

    response.data.cursos.map(data => alert(data.name))
    

    【讨论】:

      猜你喜欢
      • 2019-04-24
      • 2021-02-07
      • 1970-01-01
      • 2011-11-22
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多