React Native中的响应错误

时间:2018-07-09 11:18:52

标签: javascript reactjs react-native

  

这是我的回应

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
  

这是邮递员的回复

[
    [
        {
            "@id": 1,
            "name": "approval",
            "figure": "15",
            "type": "tile",
            "function": "auxxa.Approval",
            "url": "https://api.auxxa.com/BIMobile/GetApprovals"
        },
        {
            "@id": 1,
            "name": "returnCheque",
            "figure": "158,000.00",
            "type": "tile",
            "function": "auxxa.ReturnCheque",
            "url": "https://api.auxxa.com/BIMobile/GetApprovals"
        },
        {
            "@id": 1,
            "name": "notification",
            "figure": "12",
            "type": "tile",
            "function": "auxxa.Notification",
            "url": "https://api.auxxa.com/BIMobile/GetApprovals"
        }
    ]
]
  

在这里发布我的提取方法

fetch(url, {
  method: "GET"
})
  .then(response => response.json())
  .then(responseData => {
    //set your data here
    console.log("Landing Data " + responseData[0]);
  })
  .catch(error => {
    console.error(error);
  });
  

找不到实际问题。请帮助我解决此问题。谢谢。

3 个答案:

答案 0 :(得分:2)

您将在数组内部获取一个数组作为响应。尝试访问每个数组中的第一个条目,它应该可以工作。

您也不应该将+与字符串和数组一起使用。分别使用,分别记录它们:

fetch(url)
  .then(response => response.json())
  .then(responseData => {
    console.log("Landing Data", responseData[0][0]);
  })
  .catch(error => {
    console.error(error);
  });

答案 1 :(得分:2)

将其设置为,而不是+

console.log("Landing Data " , responseData[0]);

它只会打印数据,但您会完全了解响应方式

答案 2 :(得分:0)

尝试:

  

console.log(“着陆数据”,responseData [0] [0]);