如何从get方法获取带有方括号的API数据列表?

时间:2019-12-08 17:06:33

标签: reactjs api get axios response

此API(https://vast-shore-74260.herokuapp.com/banks?city=MUMBAI)中的

数据

    [ 
       { 
          "ifsc":"ADCB0000002",
          "bank_id":143,
          "branch":"BANGALORE",
          "address":"CITI CENTRE, 28, CHURCH STREET, OFF M. G. ROAD BANGALORE 560001",
          "city":"BANGALORE",
          "district":"BANGALORE URBAN",
          "state":"KARNATAKA",
          "bank_name":"ABU DHABI COMMERCIAL BANK"
       },
       { 
          "ifsc":"ABNA0100318",
          "bank_id":110,
          "branch":"BANGALORE",
          "address":"PRESTIGE TOWERS', GROUND FLOOR, 99 \u0026 100, RESIDENCY ROAD, BANGALORE 560 025.",
          "city":"BANGALORE",
          "district":"BANGALORE URBAN",
          "state":"KARNATAKA",
          "bank_name":"THE ROYAL BANK OF SCOTLAND N V"
       }
    ]

我正在像这样从API提取数据。由于方括号,数据无法得到响应。如何获取数组格式的数据?

axios.get(`https://vast-shore-74260.herokuapp.com/banks?city=MUMBAI`)
.then(response => {
    dataUsr = {
        data: response.data.items
    }
    this.props.allUser();
}).catch(err => {
    dataUsr = {
        error_msg: err.response.data.errors[0].message,
        data: []
    }
    this.props.allUser();
})

0 个答案:

没有答案