我正在创建一个需要 api 调用的 android 应用程序,该 api 仍在开发中,但我想创建一个虚拟改造 api 请求,该请求将返回实际的 json 值作为响应,以便我可以加快应用程序开发速度。但现在我不知道该怎么办,我在网上搜索了答案,但我似乎什么也不明白。
最佳答案
有几种方法可以做到这一点。
使用 Retrofit/Okhttp 模拟,您可以将 json 文件放置在 Assets 文件夹中,并配置 Retrofit mock/okhttp 模拟,以便在命中特定端点时将 json 文件作为响应。
Retrofit Mock [在您的应用程序中运行] https://github.com/square/retrofit/tree/master/retrofit-mock
OKHttp Mock [在您的应用程序中运行] https://github.com/square/okhttp/tree/master/mockwebserver
Json-server [在您的 PC/Mac 上运行] https://github.com/typicode/json-server
关于java - Android 上的模拟 API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59181950/