Javascript React Native API json解析数据错误:未处理的承诺拒绝:语法错误:json解析错误:无法识别的令牌'<';
我使用了fetch API,响应数据显示以下错误: 未经处理的承诺拒绝:语法错误:JSON解析错误:无法识别的令牌“@和 我也是软件工程师。 我已经检查了回复。 它给了我适当的回应 最后我自己解决了我的问题。Javascript React Native API json解析数据错误:未处理的承诺拒绝:语法错误:json解析错误:无法识别的令牌'<';,javascript,react-native,Javascript,React Native,我使用了fetch API,响应数据显示以下错误: 未经处理的承诺拒绝:语法错误:JSON解析错误:无法识别的令牌“@和 我也是软件工程师。 我已经检查了回复。 它给了我适当的回应 最后我自己解决了我的问题。 谢谢你们两位的时间和建议。看看回复。看看上面写的是什么。弄清楚为什么它以开头使用开发者工具中浏览器的网络选项卡。这将向您显示响应的实际内容。这可能是HTML格式的某种错误。你能分享一下你是如何解决这个间歇性错误的吗? _getNotificationDetails() {
谢谢你们两位的时间和建议。看看回复。看看上面写的是什么。弄清楚为什么它以
开头使用开发者工具中浏览器的网络选项卡。这将向您显示响应的实际内容。这可能是HTML格式的某种错误。你能分享一下你是如何解决这个间歇性错误的吗?
_getNotificationDetails() {
this._showLoading();
AsyncStorage.getItem('auth_token', (errs, result) => {
if (!errs) {
if (result !== null) {
auth_token = result;
this.setState({ auth_token: result });
}
}
}).then(() => {
const notificationsData = [];
let authToken = this.state.auth_token;
apitoken = `Bearer ${authToken}`;
fetch(AppConstants.getNotificationDetailsAPIURL, {
method: 'get',
headers: new Headers({
'Authorization': apitoken,
'cache-control': 'no-cache',
'Accept': "application/json",
})
}).then((response) => {
this.setState({ loading: false });
this._hideLoading();
return response.json();
}).then((responseData) => {
this.setState({ loading: false });
this._hideLoading();
if (responseData.data !== null) {
this.setState({ loading: false });
this._hideLoading();
this.setState({ notificationsData: responseData.data });
var serialNumber = 0;
const sortable = responseData.data;
console.log(sortable);
sortable.map(function (item, index) {
var getNotificationDuration = this._getNotificationDuration(sortable[index].created_at);
notificationsData.push(
<TouchableOpacity key={`${serialNumber}`} onPress={() => ""}>
<View style={styles.dataViewNotification} key={`${serialNumber}`}>
<View style={styles.fixedBoxViewDesignFirstNotification}>
<View style={styles.friendsViewRidesDesignNotification}>
<View style={styles.friendsViewInnerBoxDesignNotification}>
<View styles={{ width: 80, paddingTop: 20, borderColor: 'black', borderRadius: 1 }}>
<View style={styles.middleBoxScrollViewImageDesign}>
<Image
source={
__DEV__
? require('../assets/images/profileIcons/Profile-Bike.png')
: require('../assets/images/profileIcons/Profile-Bike.png')
}
style={styles.notificationProfileImageDesign}
/>
</View>
</View>
<View style={styles.boxMiddleContentViewDesignFriendsMainViewNotification}>
{this.state.fontLoaded ? <Text style={styles.friendsCountDesignFriendsTextNotification}>{sortable[index].body ? sortable[index].body : ''}</Text> : null}
{this.state.fontLoaded ? <Text style={styles.friendsCountDesignFriendsTextTypeNotification}>{getNotificationDuration}</Text> : null}
</View>
<View style={styles.boxLastContentViewDesignFriendsMainViewNotification}>
<TouchableOpacity onPress={() => { this.setState({ checked: !this.state.checked }) }} style={styles.checkBoxAgreeTermsAndConditionOuterDesign}>
<Entypo size={25} name="chevron-small-right" color="#292929" />
</TouchableOpacity>
</View>
</View>
</View>
</View>
</View>
</TouchableOpacity >
);
}.bind(this));
console.log(notificationsData);
this.setState({ notificationDataView: notificationsData });
}
});
});
}
{
"total": 2,
"offset": 0,
"limit": 100,
"data": [
{
"id": 19,
"body": "Wilson has sent you a friend request.",
"associated_object_id": 2,
"associated_object_type": "User",
"read": false,
"created_at": "2018-06-13T14:49:40.900+00:00"
},
{
"id": 18,
"body": "David accepted your friend request!",
"associated_object_id": 2,
"associated_object_type": "User",
"read": false,
"created_at": "2018-06-13T14:49:37.956+00:00"
}
]
}