我有 2 個(gè)屏幕;[第一個(gè)屏幕 - 這里用戶(hù)輸入手機(jī)號(hào)碼] 這個(gè)手機(jī)號(hào)碼應(yīng)該傳遞給 JSON 并驗(yàn)證這個(gè)手機(jī)號(hào)碼是否存在,如果手機(jī)號(hào)碼存在,那么它會(huì)用一些數(shù)據(jù)進(jìn)行響應(yīng)。此響應(yīng)應(yīng)傳遞到下一個(gè)屏幕。這是我的第一個(gè)屏幕代碼[用戶(hù)輸入數(shù)據(jù)的地方]-class Register extends React.Component {constructor(props) { super(props) this.state = { abc: '' } } UserLoginFunction = () =>{ const { abc } = this.state;fetch('http://demo.weybee.in/react/User_Login.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ mobileno: abc, })}).then((response) => response.json()) .then((responseJson) => { // If server response message same as Data Matched if(responseJson != 'Enter valid phone number' ) { console.log(responseJson[0]); console.log(responseJson[1]); console.log(responseJson[2]); console.log(responseJson[3]); //Then open Profile activity and send user email to profile activity. this.refs.toast.show('Login successful', 500, () => { const { navigation } = this.props; const { abc } = this.state ; navigation.navigate("Profile", { mobileno : abc, myJSON: responseJson[0]+ " " +responseJson[1], myJSON2: responseJson[2], myJSON3: responseJson[3], }, ); }); } else{ Alert.alert(responseJson); } }).catch((error) => { console.error(error); }); }
在本機(jī)反應(yīng)中發(fā)送和獲取 JSON 數(shù)據(jù) [JSON 解析錯(cuò)誤]
慕運(yùn)維8079593
2021-08-28 18:47:23