Comments (3)
这很明显是后端同学偷懒的结果,json 写成这样...我觉得与其在端上妥协,做这种 trick 的处理。还不如跟后端沟通一下,给过来标准的 json 格式。
另外我觉得 @bricklazy 提到的处理方式是最简单有效的。其实你也已经用了 RxJava,只需要再 map 一次就 ok 了。重写 Converter 就复杂了,而且也不通用。
from android-discuss.
比较笨的方法可以把 AdBaseBeanList 改成 String,数据接收到之后 用gson在转一下。
class mobileData{
/**
* publish_type : 00
* uv_value : 3
* app_type : 02
* page_type :
* customer_level : ALL_CUSTOMER
* partner_level : 0
* rule_number : 0
* click_number : 0
* title : 超时
* create_operator : zexin
* publish_operator : wangchaocheng
* optimistic : 0
* update_time : 2019-03-20 14:28:43
* pv_value : 10
* publish_time : 2019-03-20 14:28:51
* link_url : https://www.cnblogs.com/ailiailan/p/7388784.html
* id : 32
* click_type : H5
* create_time : 2019-02-26 09:36:33
* end_time : 2019-03-30 10:00:04
* link_title : CNBLOGS
* message_type : 02
* optimistic_lastsync : 0
* update_operator : wangchaocheng
* start_time : 2019-02-25 09:36:01
* image_path : http://.www.baidu.com
* popup_rule : 02
* region :
* status : NORMAL
*/
private String publish_type;
private int uv_value;
private String app_type;
private String page_type;
private String customer_level;
private String partner_level;
private int rule_number;
private int click_number;
private String title;
private String create_operator;
private String publish_operator;
private int optimistic;
private String update_time;
private int pv_value;
private String publish_time;
private String link_url;
private int id;
private String click_type;
private String create_time;
private String end_time;
private String link_title;
private String message_type;
private int optimistic_lastsync;
private String update_operator;
private String start_time;
private String image_path;
private String popup_rule;
private String region;
private String status;
public String getPublish_type() {
return publish_type;
}
public void setPublish_type(String publish_type) {
this.publish_type = publish_type;
}
public int getUv_value() {
return uv_value;
}
public void setUv_value(int uv_value) {
this.uv_value = uv_value;
}
public String getApp_type() {
return app_type;
}
public void setApp_type(String app_type) {
this.app_type = app_type;
}
public String getPage_type() {
return page_type;
}
public void setPage_type(String page_type) {
this.page_type = page_type;
}
public String getCustomer_level() {
return customer_level;
}
public void setCustomer_level(String customer_level) {
this.customer_level = customer_level;
}
public String getPartner_level() {
return partner_level;
}
public void setPartner_level(String partner_level) {
this.partner_level = partner_level;
}
public int getRule_number() {
return rule_number;
}
public void setRule_number(int rule_number) {
this.rule_number = rule_number;
}
public int getClick_number() {
return click_number;
}
public void setClick_number(int click_number) {
this.click_number = click_number;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCreate_operator() {
return create_operator;
}
public void setCreate_operator(String create_operator) {
this.create_operator = create_operator;
}
public String getPublish_operator() {
return publish_operator;
}
public void setPublish_operator(String publish_operator) {
this.publish_operator = publish_operator;
}
public int getOptimistic() {
return optimistic;
}
public void setOptimistic(int optimistic) {
this.optimistic = optimistic;
}
public String getUpdate_time() {
return update_time;
}
public void setUpdate_time(String update_time) {
this.update_time = update_time;
}
public int getPv_value() {
return pv_value;
}
public void setPv_value(int pv_value) {
this.pv_value = pv_value;
}
public String getPublish_time() {
return publish_time;
}
public void setPublish_time(String publish_time) {
this.publish_time = publish_time;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getClick_type() {
return click_type;
}
public void setClick_type(String click_type) {
this.click_type = click_type;
}
public String getCreate_time() {
return create_time;
}
public void setCreate_time(String create_time) {
this.create_time = create_time;
}
public String getEnd_time() {
return end_time;
}
public void setEnd_time(String end_time) {
this.end_time = end_time;
}
public String getLink_title() {
return link_title;
}
public void setLink_title(String link_title) {
this.link_title = link_title;
}
public String getMessage_type() {
return message_type;
}
public void setMessage_type(String message_type) {
this.message_type = message_type;
}
public int getOptimistic_lastsync() {
return optimistic_lastsync;
}
public void setOptimistic_lastsync(int optimistic_lastsync) {
this.optimistic_lastsync = optimistic_lastsync;
}
public String getUpdate_operator() {
return update_operator;
}
public void setUpdate_operator(String update_operator) {
this.update_operator = update_operator;
}
public String getStart_time() {
return start_time;
}
public void setStart_time(String start_time) {
this.start_time = start_time;
}
public String getImage_path() {
return image_path;
}
public void setImage_path(String image_path) {
this.image_path = image_path;
}
public String getPopup_rule() {
return popup_rule;
}
public void setPopup_rule(String popup_rule) {
this.popup_rule = popup_rule;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
String json= "[{"publish_type":"00","uv_value":3,"app_type":"02","page_type":"","customer_level":"ALL_CUSTOMER","partner_level":"0","rule_number":0,"click_number":0,"title":"超时","create_operator":"zexin","publish_operator":"wangchaocheng","optimistic":0,"update_time":"2019-03-20 14:28:43","pv_value":10,"publish_time":"2019-03-20 14:28:51","link_url":"https://www.cnblogs.com/ailiailan/p/7388784.html","id":32,"click_type":"H5","create_time":"2019-02-26 09:36:33","end_time":"2019-03-30 10:00:04","link_title":"CNBLOGS","message_type":"02","optimistic_lastsync":0,"update_operator":"wangchaocheng","start_time":"2019-02-25 09:36:01","image_path":"http://.www.baidu.com","popup_rule":"02","region":"","status":"NORMAL"}]";
List<mobileData> list = null;
try {
list = gson.fromJson(json, new TypeToken<List<mobileData>>(){}.getType());
}catch (Exception e){
e.printStackTrace();
}`
from android-discuss.
比较笨的方法可以把 AdBaseBeanList 改成 String,数据接收到之后 用gson在转一下。
class mobileData{
/** * publish_type : 00 * uv_value : 3 * app_type : 02 * page_type : * customer_level : ALL_CUSTOMER * partner_level : 0 * rule_number : 0 * click_number : 0 * title : 超时 * create_operator : zexin * publish_operator : wangchaocheng * optimistic : 0 * update_time : 2019-03-20 14:28:43 * pv_value : 10 * publish_time : 2019-03-20 14:28:51 * link_url : https://www.cnblogs.com/ailiailan/p/7388784.html * id : 32 * click_type : H5 * create_time : 2019-02-26 09:36:33 * end_time : 2019-03-30 10:00:04 * link_title : CNBLOGS * message_type : 02 * optimistic_lastsync : 0 * update_operator : wangchaocheng * start_time : 2019-02-25 09:36:01 * image_path : http://.www.baidu.com * popup_rule : 02 * region : * status : NORMAL */ private String publish_type; private int uv_value; private String app_type; private String page_type; private String customer_level; private String partner_level; private int rule_number; private int click_number; private String title; private String create_operator; private String publish_operator; private int optimistic; private String update_time; private int pv_value; private String publish_time; private String link_url; private int id; private String click_type; private String create_time; private String end_time; private String link_title; private String message_type; private int optimistic_lastsync; private String update_operator; private String start_time; private String image_path; private String popup_rule; private String region; private String status; public String getPublish_type() { return publish_type; } public void setPublish_type(String publish_type) { this.publish_type = publish_type; } public int getUv_value() { return uv_value; } public void setUv_value(int uv_value) { this.uv_value = uv_value; } public String getApp_type() { return app_type; } public void setApp_type(String app_type) { this.app_type = app_type; } public String getPage_type() { return page_type; } public void setPage_type(String page_type) { this.page_type = page_type; } public String getCustomer_level() { return customer_level; } public void setCustomer_level(String customer_level) { this.customer_level = customer_level; } public String getPartner_level() { return partner_level; } public void setPartner_level(String partner_level) { this.partner_level = partner_level; } public int getRule_number() { return rule_number; } public void setRule_number(int rule_number) { this.rule_number = rule_number; } public int getClick_number() { return click_number; } public void setClick_number(int click_number) { this.click_number = click_number; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getCreate_operator() { return create_operator; } public void setCreate_operator(String create_operator) { this.create_operator = create_operator; } public String getPublish_operator() { return publish_operator; } public void setPublish_operator(String publish_operator) { this.publish_operator = publish_operator; } public int getOptimistic() { return optimistic; } public void setOptimistic(int optimistic) { this.optimistic = optimistic; } public String getUpdate_time() { return update_time; } public void setUpdate_time(String update_time) { this.update_time = update_time; } public int getPv_value() { return pv_value; } public void setPv_value(int pv_value) { this.pv_value = pv_value; } public String getPublish_time() { return publish_time; } public void setPublish_time(String publish_time) { this.publish_time = publish_time; } public String getLink_url() { return link_url; } public void setLink_url(String link_url) { this.link_url = link_url; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getClick_type() { return click_type; } public void setClick_type(String click_type) { this.click_type = click_type; } public String getCreate_time() { return create_time; } public void setCreate_time(String create_time) { this.create_time = create_time; } public String getEnd_time() { return end_time; } public void setEnd_time(String end_time) { this.end_time = end_time; } public String getLink_title() { return link_title; } public void setLink_title(String link_title) { this.link_title = link_title; } public String getMessage_type() { return message_type; } public void setMessage_type(String message_type) { this.message_type = message_type; } public int getOptimistic_lastsync() { return optimistic_lastsync; } public void setOptimistic_lastsync(int optimistic_lastsync) { this.optimistic_lastsync = optimistic_lastsync; } public String getUpdate_operator() { return update_operator; } public void setUpdate_operator(String update_operator) { this.update_operator = update_operator; } public String getStart_time() { return start_time; } public void setStart_time(String start_time) { this.start_time = start_time; } public String getImage_path() { return image_path; } public void setImage_path(String image_path) { this.image_path = image_path; } public String getPopup_rule() { return popup_rule; } public void setPopup_rule(String popup_rule) { this.popup_rule = popup_rule; } public String getRegion() { return region; } public void setRegion(String region) { this.region = region; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } }
String json= "[{"publish_type":"00","uv_value":3,"app_type":"02","page_type":"","customer_level":"ALL_CUSTOMER","partner_level":"0","rule_number":0,"click_number":0,"title":"超时","create_operator":"zexin","publish_operator":"wangchaocheng","optimistic":0,"update_time":"2019-03-20 14:28:43","pv_value":10,"publish_time":"2019-03-20 14:28:51","link_url":"https://www.cnblogs.com/ailiailan/p/7388784.html","id":32,"click_type":"H5","create_time":"2019-02-26 09:36:33","end_time":"2019-03-30 10:00:04","link_title":"CNBLOGS","message_type":"02","optimistic_lastsync":0,"update_operator":"wangchaocheng","start_time":"2019-02-25 09:36:01","image_path":"http://.www.baidu.com","popup_rule":"02","region":"","status":"NORMAL"}]";
List<mobileData> list = null; try { list = gson.fromJson(json, new TypeToken<List<mobileData>>(){}.getType()); }catch (Exception e){ e.printStackTrace(); }`
感谢。
是的,这也是我目前采用的 ,但感觉很不舒服,既然我用了GsonConverterFactory,就势必想要一步到位,直接返回bean。我试图重写Converter但没有成功,我希望通过重写Converter来解决这个问题。
from android-discuss.
Related Issues (20)
- 各位遇到过对自己的内部存储空间没有访问权限的情况吗? HOT 16
- 【求助】gradle中的依赖报错,已经配置了项目仓库但是还是无法解析是什么原因?
- 华为P20 QQ 微信打开文件-其他应用打开,显示不出自己的应用图标是咋回事 HOT 6
- 怎么在VS上打开github考下来的项目?需要哪些软件?
- 【问答】国产手机如何获取锁屏通知、横幅通知权限是否打开? HOT 5
- 【提问】为什么 codekk 需要 github 用户所有的写入权限
- 【问答】Android 中通过MediaPlayer播放视频如何切换原伴唱 HOT 2
- [问答] 使用蓝牙耳机的麦克风录音的方案有哪些?
- [问答]Android SN就是存储在/vendor/nvdata/APCFG/APRDEB/PRODUCT_INFO的前64位吗?
- []
- [问答] 如何让自己的 app 中禁用第三方软件的 AccessibilityService 对其操作。
- 短视频模替换素材是怎么实现的?
- 怎么限制FlexboxLayout 一行显示的个数再换行
- Android组件化后 本地数据库如何设计 HOT 2
- 怎么限制FlexboxLayout的行数,并且多出的部分在末尾显示.....? HOT 1
- vivo 应用市场的包,无法自动更新 HOT 1
- room 存取操作
- > > @c
- 现在android使用了AOP的框架都有哪些? HOT 9
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 android-discuss.