【发布时间】:2019-04-24 03:40:36
【问题描述】:
我正在尝试使用 Moshi 解析 Json 响应,我遇到的问题是键的值是字符串上的 Json 包装:
{"mobile_accounts_account_showProperties":"[{\"name\": \"current\"},{\"name\": \"available\"}]"}
这是我的课
@Json(name = "mobile_accounts_account_showProperties")
private List<PropertyConfig> showProperties;
我尝试在解析之前使用replace("\"[", "[") 和replace("\\", "") 删除 (""),但这不是一个选项,因为这会删除我确实需要的一些其他引号。我尝试使用 JsonAdapter 但我无法做到这一点。 JsonAdapter 没有被调用。
public class PropertyConfigJsonAdapter {
public PropertyConfigJsonAdapter() {
}
@ToJson
String toJson(List<PropertyConfig> card) {
return "";
}
@FromJson
List<PropertyConfig> fromJson(String object) {
return new ArrayList<>();
}
我试试看 JsonAdapter 是否被调用,但它从不调用“fromJson”方法。以下是我如何称呼适配器:
MoshiConverterFactory.create(new Moshi.Builder().add(new PropertyConfigJsonAdapter()).build())
【问题讨论】:
标签: jsonparser moshi