public class JsonObject { private static final String TAG = "JsonObject"; private void sendRequestWithOkHttp(){ new Thread(new Runnable() { @Override public void run() { try{ OkHttpClient client =new OkHttpClient(); Request request=new Request.Builder() .url("指定地址") .build(); Response response =client.newCall(request).execute(); String responseData=response.body().string(); parseJSONWithJSONObject(responseData); }catch (Exception e){ e.printStackTrace(); } } }).start(); } private void parseJSONWithJSONObject(String jsonData){ try { JSONArray jsonArray=new JSONArray(jsonData); for(int i=0;i<jsonArray.length();i++){ JSONObject jsonObject=jsonArray.getJSONObject(i); String id=jsonObject.getString("id"); Log.d(TAG, "id:"+id); } }catch (Exception e){ e.printStackTrace(); } } }
【Android 学习记录】JsonObject解析JSON数据
最新推荐文章于 2024-07-14 03:30:14 发布