• Volley之 JsonRequest 解析JSON 数据


    ReqestQueue 和 JsonRequest

    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包哦

    compile 'com.mcxiaoke.volley:library-aar:1.0.0'

    ok完成了!

  • 相关阅读:
    P2324 [SCOI2005]骑士精神
    Codeforces Round #574 (Div. 2) A~E Solution
    P4132 [BJOI2012]算不出的等式
    spring笔记(三)
    spring笔记(二)
    C3P0连接池参数解释
    spring笔记(一)
    hibernate笔记(四)
    hibernate笔记(三)
    hibernate笔记(二)
  • 原文地址:https://www.cnblogs.com/android-host/p/5392086.html
Copyright © 2020-2023  润新知