Javascript ';JSON解析错误无法识别的令牌'<'';来自React Native';的POST请求出错;s分量
请纠正我在这个问题上的基本错误,并帮助我解决这个问题。我将非常感谢。为了纠正您的“基本错误”Javascript ';JSON解析错误无法识别的令牌'<'';来自React Native';的POST请求出错;s分量,javascript,node.js,reactjs,react-native,Javascript,Node.js,Reactjs,React Native,请纠正我在这个问题上的基本错误,并帮助我解决这个问题。我将非常感谢。为了纠正您的“基本错误”是的,似乎返回的是html而不是JSON。现在我知道了为什么这个特殊的字符是,这个问题已经解决了。URL中肯定有错误。谢谢@NeilLunni,我遇到了同样的问题,我已经用postman测试了我的api,我还测试了浏览器上的url/端点,它返回json文件。有什么问题吗?@JonasModie,如果你得到 import React from 'react'; import {StyleSheet, Tex
是的,似乎返回的是html而不是JSON。现在我知道了为什么这个特殊的字符是,这个问题已经解决了。URL中肯定有错误。谢谢@NeilLunni,我遇到了同样的问题,我已经用postman测试了我的api,我还测试了浏览器上的url/端点,它返回json文件。有什么问题吗?@JonasModie,如果你得到
import React from 'react';
import {StyleSheet, Text, View, TextInput, KeyboardAvoidingView, Keyboard, TouchableOpacity, AsyncStorage} from 'react-native';
import {StackNavigator} from 'react-navigation';
export default class Broadcast extends React.Component {
constructor(props){
super(props);
this.state ={
username: ''
}
}
componentDidMount(){
this._loadInitialState().done();
}
_loadInitialState=async()=>{
var user= await AsyncStorage.getItem('user');
console.log(user+'*********************')
if(user!==null){
this.setState({
username:user
});
}
}
render() {
this.broadcastList();
return (
<KeyboardAvoidingView behavior='padding' style={styles.wrapper}>
<View style={styles.container}>
<Text style={styles.header}>Broadcast Page</Text>
</View>
</KeyboardAvoidingView>
);
}
broadcastList=()=>{
console.log(this.state.username);
fetch(`http://192.168.137.1:3000/getBroadcastList?id=${this.state.username}`,{
method:'POST',
headers:{
'Accept':'application/json',
'Content-Type':'application/json',
},
body: JSON.stringify({
})
}) //backend IP :')
.then((response)=> response.json())
.then((res)=>{
if(res.success===true){
AsyncStorage.setItem('changeInBroadcastList',false);
AsyncStorage.setItem('broadcastList',res.broadcastList);
}
else{
AsyncStorage.setItem('loginSuccess',false);
alert(res.message);
}
})
.done();
}
}
const styles=StyleSheet.create({
wrapper:{
flex:1
},
container:{
flex:1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff0f0',
paddingLeft: 40,
paddingRight: 40
},
header:{
fontSize: 24,
marginBottom:60,
color:'#000000',
fontWeight: 'bold',
},
textInput:{
alignSelf: 'stretch',
padding:16,
marginBottom:20,
backgroundColor:'#fff',
},
btn:{
alignSelf: 'stretch',
backgroundColor:'#f0f0ff',
padding:20,
alignItems: 'center',
}
})
JSON Parse error: Unrecognized token '<'
tryCallOne
Z:\saic\crossplatform\brodSaic\node_modules\promise\setimmediate\core.js:37:14
<unknown>
Z:\saic\crossplatform\brodSaic\node_modules\promise\setimmediate\core.js:123:25
<unknown>
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:297:23
_callTimer
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:154:6
_callImmediatesPass
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:202:17
callImmediates
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:466:11
__callImmediates
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:329:4
<unknown>
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:147:6
__guardSafe
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:316:6
flushedQueue
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:146:17
invokeCallbackAndReturnFlushedQueue
Z:\saic\crossplatform\brodSaic\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:142:11