asp.net - React Native 中的 Asp.net Webservice 响应获取
问题描述
我们正在尝试在我们的 react native 中获取 webservices json 响应。我们可以在以不同方式尝试后获取。我们来自网络服务的 Json 响应是这样的{
“表”:[{“代码”:“M251”,“名字”:“MINAL JAGDISH TRIVEDI”}]}
我们在本机反应中编写的代码以获取此响应是
import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class HomeScreen extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
return fetch('URL',{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson.Table,
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => <Text>{item.code}, {item.firstname}</Text>}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}
如果有人已经遇到此问题,请提供解决方案。
解决方案
推荐阅读
- iis - 在 IIS 服务器中托管 MEAN 应用程序时,在 wwwroot 文件夹中创建的项目文件夹中的文件出现 404 错误
- reactjs - 没有找到反应浏览器路由器模块?
- php - 无法使用 file_get_contents 获取页面内容
- javascript - 通过 html 中的 Knockout 循环将值存储在变量中
- python - 以毫秒为单位获取总运行时间
- awk - grep 无法从 CSV 文件中删除模式
- react-native - 在 MainActivity.java 中找不到 onCreate()
- vb.net - 如何在 Datagridview 中获取与不同列值相关的列的不同值和列摘要
- java - GWT 编译无法运行程序 CreateProcess 错误=206
- android - 如何在独立于生命周期的类中处理 Observables?