Comments (5)
T = String 我测试过是没有问题的,你可以使用 AbsCallBck 打印一下 返回的数据能不能转成 string,如果不能的话,我那方法就会异常的,如果可以是不会的。。如果有更详细的情况,可以加群 489873144 ,在群里告诉我。
from okhttp-okgo.
因为你现在默认进了parseNetworkResponse这里就是服务器正确返回了数据,其实大多数情况下服务器数据会给一个code值来判断是不是正确返回,假如在parseNetworkResponse方法里返回的不是String而是(T) response,在BaseRequest里面会调用onResponse(T t)方法把Response传到UI线程,但此时UI线程是onResponse(String result)这个回调,类型就不匹配了
from okhttp-okgo.
这个你就可以根据自己的需要继承 AbsCallBack ,在这里面实现你自己的数据解析逻辑就可以了,例如对状态码的判断,错误消息的处理等等。。。我在demo 里面的callback包下有提供一个 CallBack 就是这么做的,你可以仿造这个写写。每个服务器对返回的状态码和消息格式都不一样,我这里没法写死,所以就得留给你们自己实现了。。
from okhttp-okgo.
我知道你说的意思了。。。我刚刚也找到了这个问题的所在。。这个问题的根源在于 JsonCallBack 中的 parseNetworkResponse 方法的具体实现。。他会自己解析用户传进来的泛型T,并返回对应的实体对象,一般情况下是没有问题的。。
但是,比如 DialogCallBAck 继承了 GlobeCallBack,而 GlobeCallBack 才继承 JsonCallBack 这时就会出现你说的问题,因为默认的 parseNetworkResponse 只能解析一层继承结构的泛型。向上面的两层,如果T 是 String,当代码运行时,parseNetworkResponse 会认为他的泛型是一个叫 T 的实体类,而不认为是一个泛型,所以代码进入了 Gson 解析。报出了 gson解析异常的错误。。
解决办法就是不用 JsonCallBack,parseNetworkResponse 每次请求的时候自己实现。虽然每次都得多写一个方法,但是不会出错。。感谢你的提问。。
from okhttp-okgo.
帮你fix了这个bug。详见 (#12)
问题:parseNetworkResponse()应该throws Exception。网络返回的数据往往不可靠,比如你想得到json数据,服务器给你返回一个404的错误页面。
解决方式:把parseNetworkResponse()的异常抛到onError和onAfter里了,框架使用者可以统一处理异常了。比如自定义一个ParseException, 在onError和onAfter里处理。
from okhttp-okgo.
Related Issues (20)
- 自己写的自用网络框架,感兴趣的看看
- upload循环上传时,会有参数复用问题
- 作者弃坑了,推荐一款新的网络请求框架 HOT 2
- QQ群被封了,有没有新群??? HOT 5
- 原群友新建QQ群:773699239,欢迎大家加入Android格调小屋
- The project has not been updated for 4 years. It is recommended to replace it with mainstream Retrofit HOT 1
- OutOfMemorryError HOT 1
- android快速接入网络库(默认通过okhttp实现,支持切换网络库)
- Google Waring
- 是否支持同步get请求
- Failed to open database '/data/user/0/com.*.*/databases/okgo.db'.
- [五年了]从开源软件精神谈谈我的感叹 HOT 4
- 参数进行转义怎么处理 HOT 1
- 格调小屋新群750467053 okgo群主已经忙的不申请了。有问题来我们这里 HOT 1
- wss请求报Caused by: java.security.cert.CertificateException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: Certificate expired at
- DBUtils HOT 1
- javax.net.ssl.SSLHandshakeException: connection closed
- 请问怎么实现类似postman单参数设置content-type
- 控制台的日志不是中文编码
- 打个广告 gson 10倍速度提升 https://github.com/NBXXF/gson_plugin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okhttp-okgo.