我正在尝试使用 Moshi 解析 Json 响应,我遇到的问题是键的值是字符串上的 Json 包装:
{"mobile_accounts_account_showProperties":"[{\"name\": \"current\"},{\"name\": \"available\"}]"}
Run Code Online (Sandbox Code Playgroud)
这是我的课
@Json(name = "mobile_accounts_account_showProperties")
private List<PropertyConfig> showProperties;
Run Code Online (Sandbox Code Playgroud)
我尝试在解析之前用 areplace("\"[", "[")和 a删除 ("")replace("\\", "")但不是一个选项,因为这删除了我确实需要的一些其他引号。我尝试使用 JsonAdapter 但我无法做到这一点。JsonAdapter 没有接到电话。
public class PropertyConfigJsonAdapter {
public PropertyConfigJsonAdapter() {
}
@ToJson
String toJson(List<PropertyConfig> card) {
return "";
}
@FromJson
List<PropertyConfig> fromJson(String object) {
return new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
我尝试这样做以查看 JsonAdapter 是否正在调用,但它从未调用过“fromJson”方法。这是我调用适配器的方式:
MoshiConverterFactory.create(new Moshi.Builder().add(new PropertyConfigJsonAdapter()).build())
Run Code Online (Sandbox Code Playgroud)