2017-09-26 57 views

回答

1
final TextView mTextView = (TextView) findViewById(R.id.text); ... 

// Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url ="http://www.google.com"; 

// Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.GET, url, 
            new Response.Listener<String>() { 
    @Override 
    public void onResponse(String response) { 
        // Display the first 500 characters of the response string. 
        mTextView.setText("Response is: "+ response.substring(0,500)); 
    } }, new Response.ErrorListener() { 
    @Override 
    public void onErrorResponse(VolleyError error) { 
        mTextView.setText("That didn't work!"); 
    } }); // Add the requestto the RequestQueue. queue.add(stringRequest); 

此代码应该代表您的问题,它可能会有所帮助。如果不是,请查看链接。 来源:https://developer.android.com/training/volley/simple.html

+0

在这段代码中,android如何获得变量“level”的值? – user3208987

+0

@ user3208987您可以在php代码中将其回显出来...... <?php echo level; ?> php网站的整个输出将被放入TextView中... – EricHier

+0

哦,我知道了,让我试试。我很快会通知你结果。 – user3208987

2

你可以建立或那种方式编码Json你也将获得,在Android的侧

KEYVALUE{ key = values }

其中

key = level(your TABLE column name)value = 1(动态值)如果您想知道如何获得column_name和编码JSON按照return JSON from mysql with column name

+0

你的意思是我必须使用Json:php值为Json和Json值为Android?你能否详细介绍一下这方面的细节,因为我对json和android很陌生。 – user3208987

+0

你可以用它的列名将json编码到你的数据库和它的值这就是它 –