使用Retrofit解析本地JSON文件中的文本 [英] Use Retrofit to parse text from JSON file in local

查看:379
本文介绍了使用Retrofit解析本地JSON文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在/res/raw中有一个JSON文本文件.阅读其文本内容后,我想使用Retrofit将JSON文本解析为Object.但是Retrofit似乎只接受来自服务器中文件的输入.

I have a JSON text file in /res/raw. After reading its text content, I would like to use Retrofit to parse JSON text to Object. But it seems Retrofit only accept input from file in server.

在这种情况下,是否仍可以重用Retrofit的JSON解析器模块?

Is there anyway to reuse Retrofit's JSON parser module in this case?

推荐答案

您只需配置Gson实例一次,然后就可以通过RestAdapter.Builder.setConverter(new GsonConverter(customGson)

You can configure Gson instance once and then just use it both for local parsing and for Retrofit via RestAdapter.Builder.setConverter(new GsonConverter(customGson)

这篇关于使用Retrofit解析本地JSON文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆