根據http://kangkaipro.blogspot.com/2018/06/android-studio-json.html
的教學
用Android studio抓了php的值
把值放在TextView顯示
GetNetworkJson的方法貌似不會把PHP的JSON格式在Android studio轉換,
加上只有要抓php輸出的數字所以沒去用成Json格式(用json格式輸出框框[]還在)
GetNetworkJson.java
package com.example.large;
import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class GetNetworkJson extends AsyncTask<String,Void,String> {
    String data = "";
    InputStream inputStream = null;
    @Override
    //doInBackground : 執行中,在背景做任務。
    protected String doInBackground(String... urlstrings) {
        try {
            URL url = new URL(urlstrings[0]); //初始化
            HttpURLConnection httpURLConnection =
                    (HttpURLConnection) url.openConnection(); //取得連線之物件
            InputStream inputStream = httpURLConnection.getInputStream();
            //輸入串流的代表物件InputStream//對取得的資料進行讀取
            BufferedReader bufferedReader =
              new BufferedReader(new InputStreamReader(inputStream));
              //宣告一個型態為BufferedReader的物件變數
              //new BufferedReader表示以BufferedReader類別建構一個物件
            // new InputStreamReader(inputStream)
            //表示接受一個inputStream物件來建構一個InputStreamReader物件
            String line = "";
            while (line != null) { //  line不等於空值的時候
                line = bufferedReader.readLine();
                //readLine讀取一行文本。
                data = data + line;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }
    protected void onPostExecute(String data) {
        super.onPostExecute(data);           
        //onPostExecute: 執行後,最後的結果會在這邊。
        MainActivity.tv.setText(data);
    }
}
MainActivity.java
package com.example.large;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    public static TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.txtJsonData);
        String url2 = "http://cclab.ocu.edu.tw/ysp105s02/TTEST/Last.php";
        GetNetworkJson process = new GetNetworkJson();
        process.execute(url2);
    }
}
如果想抓php輸出的數字到Android stuido的判斷式
除了放在TextView還有其他方法嗎???網路上搜尋抓值的部分大部分都顯示
如何抓取EditText的值:String 字串命名 = EditText的id.getText().toString();
沒有找到抓取TextView的部分.......
或是能直接抓取data的值(php顯示的值)
PHP顯示的內容
還有個不明白的地方
php檔的內容為15
TextView抓php檔顯示的值為15null
但把 while (line != null)的null去掉又會變為0
不知道該怎麼去除.......
Android studio顯示php的內容
別的先不說
把
    while (line != null) { //  line不等於空值的時候
        line = bufferedReader.readLine();
        //readLine讀取一行文本。
        data = data + line;
    }
改成
    while ((line = bufferedReader.readLine()) != null) { //  line不等於空值的時候
        //readLine讀取一行文本。
        data = data + line;
    }
試試看