Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从RESTAPI返回JSON对象_Json_Django_Reactjs_Rest - Fatal编程技术网

从RESTAPI返回JSON对象

从RESTAPI返回JSON对象,json,django,reactjs,rest,Json,Django,Reactjs,Rest,我试图从RESTAPI返回一个json对象。我正在使用django,当我从web查看对象时,我可以将数据视为json对象: [{"user": 2, "content": "please work", "members": [1], "date": "2017-11-04T21:44:23Z", "attendees": [2]}] 我试图在react中接收它,然后显示其中的内容: export default class fetchPosts { constructor(props)

我试图从RESTAPI返回一个json对象。我正在使用django,当我从web查看对象时,我可以将数据视为json对象:

[{"user": 2, "content": "please work", "members": [1], "date": "2017-11-04T21:44:23Z", "attendees": [2]}]
我试图在react中接收它,然后显示其中的内容:

export default class fetchPosts {
    constructor(props){
        this.state = {
        data: [],
        error: false,
        refreshing: false,
        url: 'http://127.0.0.1:8000/post/PostList',
        }
}
    fetchAllPosts = () => {
            fetch('http://127.0.0.1:8000/post/PostList')
            .then(res => res.json())
            .then(response => {
                this.setState({
                loading: false,
                data: response,
                refreshing: false,
            });
            console.log(data)
            return data
        })
}
} 
但是在我的react调试器中使用控制台日志返回的结果很奇怪,我知道控制台日志可能无法精确显示它,但是即使我尝试解构并呈现它,它也会告诉我承诺被拒绝或者data.content为null。

您应该尝试console.log(response)而不是console.log(data).

您应该尝试console.log(响应)而不是console.log(数据)