如何在我的React Native应用程序中获得与邮递员GET中相同的内容?

时间:2019-11-25 12:42:07

标签: 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"}}}

如何获取所需的实际内容以及邮递员给我的内容?

编辑:

我的邮递员: enter image description here

1 个答案:

答案 0 :(得分:1)

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

} 

现在使用数据集的构造函数迭代渲染项目。 并致电给您,

{item.YOUR_KEY}