javascript - 如何在我的 React Native 应用程序中获得与 postman GET 中相同的内容?

标签 javascript rest react-native

我正在与 REST 服务器通信,该服务器应该返回(这是我使用 Postman 请求它时得到的结果):

    {
        "organizer": "Fontysgroup2",
        "eventStart": "2019-11-25T11:00:00Z",
        "eventStop": "2019-11-25T11:00:00Z",
        "room": {
            "roomName": "Test Room",
            "roomEmail": null,
            "password": null
        }
    },
    {
        "organizer": "Fontysgroup2",
        "eventStart": "2019-11-25T11:00:00Z",
        "eventStop": "2019-11-25T11:00:00Z",
        "room": {
            "roomName": "Test Room",
            "roomEmail": null,
            "password": null
        }
    }
]

但是我的这段代码:


  await fetch('https://gitroom-backend.azurewebsites.net/api/Event', {
    headers: {
      Authorization: 'Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIs',
    }

  })
  .then(res => {
    console.log("content"+JSON.stringify(res))
  })
}

正在返回:


content{"type":"default","status":200,"ok":true,"headers":{"map":{"cache-control":"public, max-age=0","date":"Mon, 25 Nov 2019 13:14:09 GMT","set-cookie":"ARRAffinity=84e8f0e39af3bde1a8c7117e525b046a8722dc904bb8684ace19b555cc8f3590;Path=/;HttpOnly;Domain=gitroom-backend.azurewebsites.net","x-powered-by":"ASP.NET","request-context":"appId=cid-v1:65c12a05-4adc-4521-b71d-69ccdcb78d9f","server":"Microsoft-IIS/10.0","vary":"Accept-Encoding","content-type":"application/json; charset=utf-8","transfer-encoding":"chunked"}},"url":"https://gitroom-backend.azurewebsites.net/api/Event","_bodyInit":{"_data":{"size":331,"offset":0,"blobId":"7592c623-fb09-415e-92f7-a97e75b08d37"}},"_bodyBlob":{"_data":{"size":331,"offset":0,"blobId":"7592c623-fb09-415e-92f7-a97e75b08d37"}}}

我如何访问我想要的实际内容以及 postman 给我的内容?

编辑:

我的 postman : enter image description here

最佳答案

fetchData = async () => {
      const response = await fetch(
        "YOUR_URL"
      );
        const json = await response.json();

} 

现在使用数据集的构造函数迭代渲染项目。 并通过以下方式调用您的 View :

{item.YOUR_KEY}

关于javascript - 如何在我的 React Native 应用程序中获得与 postman GET 中相同的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59032102/

相关文章:

javascript - 如何在单个静态 HTML 中显示 2-3 个 AMcharts

javascript - jQuery - 根据前缀获取元素类

rest - HTTP API : Communicating the need to authenticate to a third party

reactjs - React Navigation - 自定义标题动画

android - 无法在获取 react 原生时设置状态

javascript - spread 方法对对象有效吗?你如何复制一个对象?

javascript - 验证 : How to preselect active tab?

javascript - 需要帮助了解 OAuth2 工作流程和选择授权类型

rest - 对于不存在的REST资源,什么时候返回404,什么时候返回403?

javascript - 可能的未处理的 Promise 拒绝 - React-Native with Firebase