redux-thunk fetch parse response

时间:2016-06-19 14:35:31

标签: javascript reactjs redux-thunk facebook-redex

我是redux和reactjs的新手,我正在尝试将一些服务器端数据提取到我的代码中。

这是我的thunk fetch:

fetch(`/WebApp/Dashboard/CreateAlert`).then(response => {
    console.log(response);
});

这是我在控制台中看到的:

enter image description here

在小提琴手中,我看到响应是“成功”的预期。

此回复是否有效,如何解析,我有点困惑,网上的信息很少。

修改

我改为:

fetch(url).
then(response => response.json())
.then(json => {
    console.log(json);
});

我收到了这个对象。现在,当我发送一个复杂类型(List)时,我看到了下面的文字:

enter image description here

1 个答案:

答案 0 :(得分:1)

如果要解析json响应:

fetch(`/WebApp/Dashboard/CreateAlert`)
    .then(response => response.json())
    .then(json => {
        console.log(json);
    });

有关可用于解析响应正文的所有方法,请参阅https://developer.mozilla.org/en-US/docs/Web/API/Body