简体   繁体   English

React Native中的响应错误

[英]Response error in React Native

Here What I have got as a response 这是我得到的回应

[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]

This is the Postman response 这是邮递员的回应

[
    [
        {
            "@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"
        }
    ]
]

Here I post my fetch method 我在这里发布我的提取方法

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);
  });

Could not find the actual issue.Please help me to sort out this issue.Thanks in advanced. 找不到实际问题。请帮助我解决此问题。谢谢。

You are getting an array inside an array as response. 您将在数组内部获取一个数组作为响应。 Try accessing the first entry in each array and it should work. 尝试访问每个数组中的第一个条目,它应该可以工作。

You should also not use + with a string and an array. 您也不应将+与字符串和数组一起使用。 Log them separately instead with , : 分别记录它们,而不用,

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

make it , instead of + . 使,而不是+

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

It will just print the data, but you will get whole idea of your responce 它只会打印数据,但是您将完全了解响应

try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM