我正在尝试制作一个连接到 API(通过 URL)的应用程序以检索过去研讨会的 session 。 API 以 JSON 格式返回所有数据。我已经尝试做几个教程(使用 Twitter API),但它们没有用。这是教程的链接:http://www.vogella.com/articles/AndroidJSON/article.html
有什么帮助吗?
最佳答案
我想重新开始使用 Retrofit。 更少的代码并获得更好的性能。 http://square.github.io/retrofit/
您可以找到许多代码示例和支持。
你可以在接口(interface)中定义你的API
public interface GitHubService {
@GET("users/{user}/repos")
Call<List<Repo>> listRepos(@Path("user") String user);
}
并设置 API 的主要 URL
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com/")
.build();
GitHubService service = retrofit.create(GitHubService.class);
最后一步,Retrofit 会将响应 Json 转换为正确的 Collection
Call<List<Repo>> repos = service.listRepos("octocat");
关于java - 如何将 Android 应用程序连接到 API 并在列表中显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12518364/