Json TypeScript从成功接收的承诺中访问数据

Json TypeScript从成功接收的承诺中访问数据,json,reactjs,typescript,promise,Json,Reactjs,Typescript,Promise,我正在使用带有TypeScript的React框架。 我的问题是,我试图使用fetch方法从成功接收的承诺中访问数据。这样我就可以(在浏览器控制台中)看到promise中有一个包含所需数据的数组。这是我的浏览器控制台输出: 组件装载并将结果保存到以下状态后,将立即执行提取: constructor(){ super(); this.processJSON = this.processJSON.bind(this); this.state = { b

我正在使用带有TypeScript的React框架。 我的问题是,我试图使用fetch方法从成功接收的承诺中访问数据。这样我就可以(在浏览器控制台中)看到promise中有一个包含所需数据的数组。这是我的浏览器控制台输出:

组件装载并将结果保存到以下状态后,将立即执行提取:

    constructor(){
    super();
    this.processJSON = this.processJSON.bind(this);
    this.state = {
        buecherJSON : []
    }
}

componentDidMount() {
    fetch('http://localhost:8080/buecher/findAllByIsbnIsBefore?anzahl=2')
        .then(results => {
            this.setState({
                buecherJSON : results.json()
            });
        })
        .catch((error) => {
            console.error(error);
        });
}
在另一个方法中,我希望处理JSON格式的数据,以使其成为一个对象。但我不知道怎么做。到目前为止,我得到了这个(基本上什么都不做):


如何将接收到的JSON映射到TypeScript中的可访问数组?

以及您计划在什么时候使用
processJSON
?目前它作为按钮onClick事件执行:Verarbeite JSON只是为了理解基本处理。不清楚您的问题是什么。因此,使用
this.state.buecherJSON
并随意使用它。基本上,我只想知道如何正确处理存储在state中的接收到的JSON数据。如:this.state.buecherJSON.author和您计划如何使用
processJSON
,在什么时候?目前它作为按钮onClick事件执行:Verarbeite JSON只是为了理解基本的处理。不清楚您的问题是什么。因此,使用
this.state.buecherJSON
并随意使用它。基本上,我只想知道如何正确处理存储在state中的接收到的JSON数据。如:this.state.buecherJSON.author
    processJSON(){

    var buecherJSON = this.state;
    console.log(Object.assign({},buecherJSON));
}