英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论