安卓。JSON解析器在我的新模块中返回null。

huangapple go评论67阅读模式
英文:

Android. JSON parser return null in my new module

问题

我在我的项目中创建了一个新模块,需要解析 JSON 文件,但解析器(我使用了 GSON)返回为 null。在项目中创建该模块之前,解析器是正常工作的。文件中的 JSON 字符串是正确的。

file.json

{"link":"https://google.com/","title":"Google"}

解析方法

BrowserLink browserLink = gson.fromJson(json, BrowserLink.class);

BrowserLink.java

public class BrowserLink {
    private String title;

    private String link;

    @NonNull
    @Override
    public String toString() {
        return "title: " + title + "; link: " + link;
    }
}

browserLink.toString() 的结果

title = title: null; link: null

我应该如何调整这个模块使解析器正常工作?

英文:

I created a new module in my project where I need parse JSON file, but parser(I used GSON) returns null. Before the module was created in the project, the parser worked. Json string from file is correct.

file.json

{"link":"https://google.com/","title":"Google"}

how I parse

BrowserLink browserLink = gson.fromJson(json, BrowserLink.class);

BrowserLink.java

public class BrowserLink {
    private String title;

    private String link;

    @NonNull
    @Override
    public String toString() {
        return "title: " + title + "; link: " + link;
    }
}

Result from browserLink.toString()

title = title: null; link: null

What should I do with the module for work parser?

答案1

得分: 0

已修复:在Android Studio和Gradle更新后
链接:https://developer.android.com/studio/write/java8-support#library-desugaring

英文:

Fixed after Android Studio and Gradle update
https://developer.android.com/studio/write/java8-support#library-desugaring

huangapple
  • 本文由 发表于 2020年5月29日 04:52:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/62074335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定