好友
阅读权限10
听众
最后登录1970-1-1
|
您提醒我**Wallet是空的,我把getGuid这个方法名对应的**Wallet.smali转为Java,注意到以下代码
[Java] 纯文本查看 复制代码 package com.huiyou.xiaoding.common.model.wallet;
import com.huiyou.xiaoding.common.model.base.HYModel;
public class HYWallet extends HYModel (
private String alias;
private String avatarUri;
......(省略)
private String guid
......(省略)
意思是导入HYModel这个包,然后HYWallet这个类继承了HYModel这个类并扩展,我理解对吗?
如果这样理解是对的,那我应该到HYModel.smali里去写值是吗?
我打开HYModel.smali转Java看到这样的代码,他也是导入别的包作为数据来源的
[Java] 纯文本查看 复制代码 package com.huiyou.xiaoding.common.model.base;
import com.huiyou.xiaoding.common.utils.DataVOUtils;
import java.util.HashMap
public class HYModel {
public String zb_jsonValue(){
return DataVOUtils.jsonValue(this);
}
public HasMap<String, Object> zb_mapValue(){
return DataVOUtils.mapValue(this);
}
}
我又该去DataVOUtils写值对吧?DataVOUtils.smali代码全文如下
[Java] 纯文本查看 复制代码 .class public Lcom/huiyou/xiaoding/common/utils/DataVOUtils;
.super Ljava/lang/Object;
.source "DataVOUtils.java"
# direct methods
.method public constructor <init>()V
.registers 1
.line 13
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static buildObjc(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
.registers 4
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava/lang/Object;",
"Ljava/lang/Class<",
"TT;>;)TT;"
}
.end annotation
.line 16
invoke-static {p0}, Lcom/huiyou/xiaoding/common/utils/StringUtils;->isNullOrEmpty(Ljava/lang/Object;)Z
move-result v0
const/4 v1, 0x0
if-eqz v0, :cond_8
return-object v1
.line 20
:cond_8
:try_start_8
invoke-static {p0}, Lcom/huiyou/xiaoding/common/utils/DataVOUtils;->jsonValue(Ljava/lang/Object;)Ljava/lang/String;
move-result-object p0
.line 21
invoke-static {p0, p1}, Lcom/alibaba/fastjson/JSON;->parseObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
move-result-object p0
:try_end_10
.catch Ljava/lang/Exception; {:try_start_8 .. :try_end_10} :catch_11
return-object p0
:catch_11
move-exception p0
.line 24
invoke-virtual {p0}, Ljava/lang/Exception;->toString()Ljava/lang/String;
move-result-object p0
const-string p1, "DataVOUtils"
invoke-static {p1, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I
return-object v1
.end method
.method public static buildObjc(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
.registers 4
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava/lang/String;",
"Ljava/lang/Class<",
"TT;>;)TT;"
}
.end annotation
.line 30
invoke-static {p0}, Lcom/huiyou/xiaoding/common/utils/StringUtils;->isNullOrEmpty(Ljava/lang/Object;)Z
move-result v0
const/4 v1, 0x0
if-eqz v0, :cond_8
return-object v1
.line 34
:cond_8
:try_start_8
invoke-static {p0, p1}, Lcom/alibaba/fastjson/JSON;->parseObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
move-result-object p0
:try_end_c
.catch Ljava/lang/Exception; {:try_start_8 .. :try_end_c} :catch_d
return-object p0
:catch_d
move-exception p0
.line 37
invoke-virtual {p0}, Ljava/lang/Exception;->toString()Ljava/lang/String;
move-result-object p0
const-string p1, "DataVOUtils"
invoke-static {p1, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I
return-object v1
.end method
.method public static buildObjcs(Ljava/lang/String;Ljava/lang/Class;)Ljava/util/List;
.registers 3
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava/lang/String;",
"Ljava/lang/Class<",
"TT;>;)",
"Ljava/util/List<",
"TT;>;"
}
.end annotation
.line 43
invoke-static {p0}, Lcom/huiyou/xiaoding/common/utils/StringUtils;->isNullOrEmpty(Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_8
const/4 p0, 0x0
return-object p0
.line 46
:cond_8
invoke-static {p0, p1}, Lcom/alibaba/fastjson/JSON;->parseArray(Ljava/lang/String;Ljava/lang/Class;)Ljava/util/List;
move-result-object p0
return-object p0
.end method
.method public static jsonValue(Ljava/lang/Object;)Ljava/lang/String;
.registers 1
if-nez p0, :cond_5
const-string p0, ""
return-object p0
.line 54
:cond_5
invoke-static {p0}, Lcom/alibaba/fastjson/JSON;->toJSONString(Ljava/lang/Object;)Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method public static mapValue(Ljava/lang/Object;)Ljava/util/HashMap;
.registers 2
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Object;",
")",
"Ljava/util/HashMap<",
"Ljava/lang/String;",
"Ljava/lang/Object;",
">;"
}
.end annotation
.line 60
invoke-static {p0}, Lcom/huiyou/xiaoding/common/utils/DataVOUtils;->jsonValue(Ljava/lang/Object;)Ljava/lang/String;
move-result-object p0
const-class v0, Ljava/util/Map;
invoke-static {p0, v0}, Lcom/alibaba/fastjson/JSON;->parseObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
move-result-object p0
check-cast p0, Ljava/util/Map;
.line 61
new-instance v0, Ljava/util/HashMap;
invoke-direct {v0, p0}, Ljava/util/HashMap;-><init>(Ljava/util/Map;)V
return-object v0
.end method
DataVOUtils.smali转换为Java如下
[Java] 纯文本查看 复制代码 package com.huiyou.xiaoding.common.utils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DataVOUtils {
public static <T> T buildObjc(Object obj, Class<T> cls) {
if (StringUtils.isNullOrEmpty(obj)) {
return null;
}
try {
return (T) JSON.parseObject(jsonValue(obj), cls);
} catch (Exception e) {
Log.e("DataVOUtils", e.toString());
return null;
}
}
public static <T> T buildObjc(String str, Class<T> cls) {
if (StringUtils.isNullOrEmpty(str)) {
return null;
}
try {
return (T) JSON.parseObject(str, cls);
} catch (Exception e) {
Log.e("DataVOUtils", e.toString());
return null;
}
}
public static <T> List<T> buildObjcs(String str, Class<T> cls) {
if (StringUtils.isNullOrEmpty(str)) {
return null;
}
return JSON.parseArray(str, cls);
}
public static String jsonValue(Object obj) {
return obj == null ? "" : JSON.toJSONString(obj);
}
public static HashMap<String, Object> mapValue(Object obj) {
return new HashMap<>((Map) JSON.parseObject(jsonValue(obj), Map.class));
}
}
貌似是涉及到判断,json字串符与对象转换之类的内容了,又是一个新的知识点,再麻烦大佬看看下一步该怎么做(小声问一句:我对这几个包的立关系理解是——DataVOUtils从服务器获取用户信息并转换格式,Model从DataVOUtils获取成果分门别类区分开用户的各条信息并组装,形成用户模型,其他的包比如Wallet要获取什么信息就从Model里获取,是不是啊?) |
|