我只是一個初學者所以幫助我!我想在本機 TextInput 中獲得 JSON 響應。[我在本機應用程序中有 2 頁。在第一頁 ==> 我想要該 JSON 數(shù)據(jù)并導航到帶有該 JSON 響應的第二頁。我使用 PHP 作為服務器端腳本語言。我的PHP代碼是:<?php// Importing DBConfig.php file.include 'DBConfig.php';// Creating connection. $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName); // Getting the received JSON into $json variable. $json = file_get_contents('php://input'); // decoding the received JSON and store into $obj variable. $obj = json_decode($json,true);// Populate column from JSON $obj array and store into $coulmn.$firstname = $obj['firstname'];$lastname = $obj['lastname'];//$mobileno = $obj['mobileno'];$email = $obj['email'];$profession = $obj['profession'];$mobileno = '7874853188';//Applying User Login query with mobile number match.$Sql_Query = "select firstname,lastname,email,profession from member where mobileno = '$mobileno' ";// Executing SQL Query.$check = mysqli_fetch_array(mysqli_query($con,$Sql_Query));if(isset($check)){ $SuccessLoginMsg = 'Data Matched'; // Converting the message into JSON format.$SuccessLoginJson = json_encode($SuccessLoginMsg); $first_name = $check[0]; $last_name = $check[1]; $email = $check[2]; $profession = $check[3];// Echo the message. echo $SuccessLoginJson ; } else{ // If the record inserted successfully then show the message.$InvalidMSG = 'Enter valid phone number' ;// Converting the message into JSON format.$InvalidMSGJSon = json_encode($InvalidMSG);// Echo the message. echo $InvalidMSGJSon ; } mysqli_close($con);?>上面的代碼是 100% 正確的。[在網(wǎng)頁上測試]在我的本機代碼中,首先我檢查手機號碼 => 如果手機號碼正確[存在于數(shù)據(jù)庫中],那么該用戶可以使用該 JSON 響應轉到下一頁。
在 React Native 的 TextInput 中獲取 json 數(shù)據(jù)
慕運維8079593
2021-08-28 15:36:14