当前位置:首页 > Android > 正文内容

Android 网络请求后的JSON解析

3年前 (2021-03-15)Android

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

扫描二维码推送至手机访问。

版权声明:本文由小祥子的博客发布,如需转载请注明出处。

本文地址:http://www.xiaoxiangzi.com/post/92.html

相关文章

Android常用第三方框架

分类二级分类框架名称简介UI刷新SmartRefreshLayout智能下拉刷新框架UI刷新Android-PullToRefresh比较早的一款下拉刷新框架UI刷新android-Ultra-Pul...

Android PopupWindow的基本使用

需求:希望点击文本区域的时候,在手指处添加一个控件,开始想到的是相对布局,添加一个隐藏层,根据点击然后显示并且重设坐标,后来发现这个方向是错的,甚至有点蠢,后来看到了popupWindow。Popup...

Android根据关键词标红部分文字

            String mKeyWord =&...

Activity的生命周期与iOS UIViewController对比

一个页面或APP的生命周期,对开发尤为重要,知道生命周期,才知道代码应该写在哪里。刚开始学iOS的时候,也因为没有深入了解页面的生命周期导致出了一些奇怪的bug。Android Activity的生命...

Android Intent界面之间的跳转

当前页面跳转到NextActivity页面Intent intent = new Intent(this,NextActivity.class) this.s...

安卓 获取TextView手指点击所在位置的文字

TextView tv;     public final static String HTML_TEX...