ReqestQueue 和 JsonRequestphp
String jsonUrl = "http://ip.taobao.com/service/getIpInfo.php?ip=63.223.108.42&qq-pf-to=pcqq.group"; //JSON 的url RequestQueue mRequestQueue = Volley.newRequestQueue(this); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, jsonUrl, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { textView.setText("JSON: " + response.getJSONObject("data").getString("country"));//處理本身的JSON數據,根據本身的key來取值就好了 } catch (JSONException e) { e.printStackTrace(); textView.setText("exception"); } }}, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { textView.setText("error"); } }); //添加到requestQueue mRequestQueue.add(jsonObjectRequest);
而後簡單的一個JSON解析就完成了,仍是不要忘記加volley包哦json
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
ok完成了!ide