Javascript &引用;找不到变量:X";使用从URL获取时出错

Javascript &引用;找不到变量:X";使用从URL获取时出错,javascript,react-native,Javascript,React Native,在React native中,我想从web URL检索js数据并使用它。这是我的密码: export default class Test extends Component { constructor(props) { super(); this.subscription = 0; this.state = { }; changePage = props.cb; console.log("

在React native中,我想从web URL检索js数据并使用它。这是我的密码:

export default class Test extends Component {

    constructor(props) {
        super();
        this.subscription = 0;
        this.state = {
        };
        changePage = props.cb;
        console.log("props", props);


      render(){

        return (
            <Container  ref="park-places-ref">

                <View style={styles.viewmain}>

                <View style={styles.viewborder}>

                </View>

          fetch('https://online.ssm.it/php/mobile/parkinfo') // Call the fetch function passing the url of the API as a parameter
          .then((response) => response.json()) // Transform the data into json
            data={response.body}
          })
            .catch(function() {
                // This is where you run code if the server returns any errors
            });

                <FlatList
                ItemSeparatorComponent={ () => <View style={ styles.rowSep } /> }

                Mydata={data}


                renderItem={

                    ({item}) => (
                    <View style={styles.row}>
                        <View style={styles.circle}   backgroundColor= {item.color}/>
                        <View style={styles.column}>
                            <Text style={styles.itemBold}>{item.extensioname}</Text>
                            <Text style={styles.itemNormal}>{item.free}</Text>

                            <Text style={styles.itemBold}>{item.freeplaces}</Text>


                        </View>
                    </View>
                    )
                }
                keyExtractor={item => item.extensioname}
                />
                </View>


            </Container>
        );
    }
}
导出默认类测试扩展组件{
建造师(道具){
超级();
本次认购=0;
此.state={
};
changePage=props.cb;
控制台日志(“道具”,道具);
render(){
返回(
取('https://online.ssm.it/php/mobile/parkinfo')//调用fetch函数,将API的url作为参数传递
.then((response)=>response.json())//将数据转换为json
数据={response.body}
})
.catch(函数(){
//这是在服务器返回任何错误时运行代码的地方
});
}
Mydata={data}
伦德雷特={
({item})=>(
{item.extensioname}
{item.free}
{item.freeplaces}
)
}
keyExtractor={item=>item.extensionName}
/>
);
}
}
}

每当我试图检索数据体时,我都无法检索它,它会显示一个错误: 我需要使用下表中的数据:

找不到变量:响应


你能帮我解决这个问题吗?如果你需要更多的信息,请告诉我

在fetch()函数调用中实际上还需要一个链

fetch( ... )
.then((response)=>response.json())
.then((resp)=> data={resp})
.catch( ... );

查看文档:

请添加一个显示实际问题的文档。现在这只是一个语法错误…data={response}})可能与它有关。@Andreas:我现在将更新它…@Andreas:我已经添加了它,它足够了吗?fetch(…)。然后((response)=>response.json())data={response.body}.catch(function(){…})仍然无效(语法错误),我看不到您在代码中使用数据变量的任何地方。如果您确实从fetch调用中得到响应,则resp将存在