OkHttp + Gson

来源:互联网 发布:淘宝网开店要交钱吗 编辑:程序博客网 时间:2024/05/22 17:40
 OkHttpClient mClient = new OkHttpClient();        Request mRequest = new Request.Builder()                .url("http://192.168.199.110:8080/mockjs/1/getLoadingSheetList?")                .build();        mClient.newCall(mRequest).enqueue(new Callback() {            @Override            public void onFailure(Call call, IOException e) {            }            @Override            public void onResponse(Call call, final Response response) throws IOException {                Gson gson = new Gson();                String result = response.body().string();                Log.e("message", result);                mJsonDriver = new JsonDriver();                mJsonDriver = gson.fromJson(result, JsonDriver.class);                            final  int count = mJsonDriver.getCount();                            Log.e("message2", String.valueOf(count));                final String endStation = mJsonDriver.getDataList().get(0).getEndStation();                Log.e("message2", endStation);                runOnUiThread(new Runnable() {                    @Override                    public void run() {                        mTextView.setText(endStation);                    }                });            }        });

0 0