安卓请求解析

作者: 螢火蟲的瘋狂 | 来源:发表于2018-06-13 11:03 被阅读0次

 Map paramsparams= new HashMap<>();    传入得参数

params.put("key", value); 

OkHttpUtils.post()               //请求数据

        .url(URL路径)

        .params(params)

        .build()

        .execute(new StringCallback() {

            @Override

            public void onError(Call call, Exception e, int id) {

//失败时

            }

            @Override

            public void onResponse(String response, int id) {  

//json原生解析

                JSONObject jsonObject= JSONObject.parseObject(response);

                String code= jsonObject.getString("errorCode");

                if (code.equals("2000")) {

                    Num= jsonObject.getString("json");

                }  

//gson解析

UserInfoBean bean= new Gson().fromJson(response, UserInfoBean.class);

}

        });

相关文章

网友评论

    本文标题:安卓请求解析

    本文链接:https://www.haomeiwen.com/subject/iufjeftx.html