将数组从Android传递到phpmysql数据库

时间:2018-11-29 13:00:47

标签: android json

我已经从android的mysql数据库中获取了数据,现在通过复选框,我想将检查后的值提交到数据库中。如何完成?我是android的新手。这是我获取数据的代码

    protected String doInBackground(String... params)
    { String result = "";
        /*Intent intent =getIntent();
        String Courseno =intent.getStringExtra(Main3Activity.Courseno);
        textViewCourse.setText(Courseno); */
        String courseno = "CSE3202" ;
        String host = "http://192.168.0.105/fetch.php?course=CSE3202";
        try {URL url = new URL(host);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            InputStream in = new BufferedInputStream(conn.getInputStream());
            result = convertStreamToString(in);
        }
        catch (Exception e)
        {
            return new String("Ther exception: " +e.getMessage());
        }

        return result;
    }

    @Override
    protected void onPostExecute(String result) {
        try{
            Log.d("ededed","ee"+result);
            JSONObject jsonResult = new JSONObject(result);
            int success =jsonResult.getInt("success");
            if(success==1)
            {
                ArrayList<Integer> arrayList = new ArrayList<Integer>();
                JSONArray students = jsonResult.getJSONArray("Courseno");
                for (int i=0; i< students.length(); i++)
                {
                    JSONObject student= students.getJSONObject(i);
                    Integer rollno = student.getInt("Rollno");
                  /*  String firstname =student.getString("firstname;");
                    String lastname =student.getString("lastname;");
                    String line = rollno + "-" + firstname + "-" + lastname; */
                    String line = rollno + "";
                    users.add(new UserModel(false, line));
                }
            }

0 个答案:

没有答案