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完成了!
posted on 2016-04-14 17:58 傻啦吧唧的程序员丶 阅读(1437) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步