Android 网络请求后的JSON解析
JSON解析用阿里巴巴的fastjson。
implementation 'com.alibaba:fastjson:1.1.71.android'
根据上一篇文章,登录接口登录后,加上JSON解析之后是这样。
public void onResponse(SimpleResponse<String, String> response) { if (response.isSucceed()){ Log.i("cwx",response.succeed()+"<="); UserInfo info = JSON.parseObject(response.succeed(),UserInfo.class); if (info.getCode() == 0){ Log.i("cwx","login successed"); }else{ Log.i("cwx","login failed"); } }else{ Log.i("cwx",response.failed()); } }
UserInfo是我后面建的一个实体类
其中code是Int类型,如果登录成功,服务器会返回0,有错误则返回1