我正在尝试在我的详细信息页面中显示数据。当我单击索引屏幕中的查看按钮时。它将直接转到详细信息页面屏幕。因此,我单击了面临此[SyntaxError: JSON Parse error: Unexpected EOF]
问题的查看按钮。
我的API代码:
//get data from api
_loadInitialState = async () => {
const token = await AsyncStorage.getItem('token');
const myArray = await AsyncStorage.getItem('language_type');
_onSetLanguage(myArray)
var loadAll = this.props.navigation.getParam('loadAll');
if (loadAll == true) { this.setState({ isLoading: true }) }
var have_access = this.props.navigation.getParam('have_access');
if (have_access != undefined) { this.setState({ have_access: have_access }) }
if (staticData.get_centre_settings() != null) { this.setState({ have_access: true }) }
let today = Moment();
this.setState({
today: Moment(today).format('YYYY-MM-DD'),
})
this.setState({ token: token });
var staff_id = this.props.navigation.getParam('id');
this.setState({ staff_id: staff_id });
fetch(FetchURL.get_baseURL() + "leave/" + staff_id , {
method: 'GET',
headers: {
'Authorization': 'Bearer '+ token,
}
})
.then(response => response.json())
.then((json) => {
alert(json)
if (json.error) {
alert(json.error);
} else {
this.setState({
staffLeave: json,
isLoading: false
});
}
})
.catch((err) => {
console.log(err)
alert(err)
// alert(strings.data_fail);
})
this.setState({ view_access: true })
}
我认为API正常运行,因为我在POSTMAN中测试了API。显示了我的数据。