Javascript 未捕获(承诺中)语法错误:获取数据时JSON输入意外结束

Javascript 未捕获(承诺中)语法错误:获取数据时JSON输入意外结束,javascript,reactjs,Javascript,Reactjs,有没有办法检查数据是否已经提取?因为当我调试代码时,它收到了以下错误- 未捕获(承诺中)语法错误:JSON输入意外结束 我已经尝试过调试,也尝试过使用不同的api 另外,当我在postman中测试API时,我能够收到响应,从中我可以得出API工作正常的结论 谁能纠正我,指出我哪里做错了,因为我是新的反应 下面是代码- import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { Table

有没有办法检查数据是否已经提取?因为当我调试代码时,它收到了以下错误-

未捕获(承诺中)语法错误:JSON输入意外结束

我已经尝试过调试,也尝试过使用不同的api

另外,当我在postman中测试API时,我能够收到响应,从中我可以得出API工作正常的结论

谁能纠正我,指出我哪里做错了,因为我是新的反应

下面是代码-

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Table } from 'react-bootstrap';
import * as Constants from '../constant'
class ViewUser extends Component {

    constructor(props) {
        super(props);
        this.state = {
            myJson: [
                { username: null, createdDate: null, createdBy: null }
            ],

        };

    }


    componentDidMount() {
        fetch(Constants.API_URL + 'api/user', {
            method: 'GET',
            headers: {
                "Authorization": "Bearer 733a7570-c39a-4fff-99e8-bcc38c1aad58",
                "Content-Type": "application/json"
            }
        })
            .then(function (response) {
                console.log(response)
                return response.json();

            })
            .then((myJson) => {
                this.setState({
                    myJson: myJson
                });
                console.log(myJson)

            });


    }

    delete = (myJson) => {
        console.log(myJson)
        const requestOptions = {
            method: 'DELETE',
            headers: {
                "Authorization": "Bearer 733a7570-c39a-4fff-99e8-bcc38c1aad58",
                "Content-Type": "application/json"
            }

        }

        fetch(Constants.API_URL + 'api/authority/' + myJson.authority, requestOptions)
            .then(response => response.text())

    }

    edit = (myJson) => {
        // Do whatever you want
        console.log(myJson)
        // history.push("/editAuthority")
        this.props.history.push({
            pathname: 'authority' + "/" + myJson.authority,
            state: { authority: myJson.authority, description: myJson.description }

        })
    }

    render() {

        return (
            <div className="container-fluid">
                <Table striped bordered hover variant="dark">
                    <thead>
                        <tr>
                            <th>username</th>
                            <th>createdDate</th>
                            <th>createdBy</th>
                            <th></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {
                            this.state.myJson.map((item, key) => {

                                return (

                                    <tr key={key} >

                                        <td>{item.username}</td>
                                        <td>{item.createdDate}</td>
                                        <td>{item.createdBy}</td>
                                        <td><center><button className="btn btn-primary btn-xs" onClick={() => this.edit(item)}>Edit
                                        </button></center></td>
                                        <td><center><button className="btn btn-primary btn-xs" onClick={() => this.delete(item)}>Delete
                                        </button></center></td>
                                    </tr>
                                )

                            })}

                    </tbody>
                </Table>
            </div>
        );
       }
     }



    export default ViewUser;
import React,{Component}来自'React';
从“react dom”导入react dom;
从'react bootstrap'导入{Table};
将*作为常量从“../constant”导入
类ViewUser扩展组件{
建造师(道具){
超级(道具);
此.state={
myJson:[
{username:null,createdDate:null,createdBy:null}
],
};
}
componentDidMount(){
获取(Constants.API_URL+'API/user'{
方法:“GET”,
标题:{
“授权”:“持有人733a7570-c39a-4fff-99e8-bcc38c1aad58”,
“内容类型”:“应用程序/json”
}
})
.然后(功能(响应){
console.log(响应)
返回response.json();
})
。然后((myJson)=>{
这是我的国家({
myJson:myJson
});
console.log(myJson)
});
}
删除=(myJson)=>{
console.log(myJson)
常量请求选项={
方法:“删除”,
标题:{
“授权”:“持有人733a7570-c39a-4fff-99e8-bcc38c1aad58”,
“内容类型”:“应用程序/json”
}
}
fetch(Constants.API_URL+'API/authority/'+myJson.authority,requestOptions)
.then(response=>response.text())
}
编辑=(myJson)=>{
//你想干什么就干什么
console.log(myJson)
//history.push(“/editAuthority”)
这个。道具。历史。推({
路径名:'authority'+“/”+myJson.authority,
状态:{authority:myJson.authority,description:myJson.description}
})
}
render(){
返回(
用户名
创建日期
创造的
{
this.state.myJson.map((项,键)=>{
返回(
{item.username}
{item.createdDate}
{item.createdBy}
this.edit(item)}>edit
this.delete(item)}>delete
)
})}
);
}
}
导出默认视图用户;

Change
returnresponse.json()
to
const text=wait response.text();console.log(文本);返回JSON.parse(text)。你看到了什么?共享你的响应结构NVM,我得到了eror,这是因为当我在那里获取数据时,会导致数据eror为空