Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

retrofit - How to parse a json local file with moshi in Kotlin

Currently I am working with an api and I use RetroFit-2 and moshi to parse it to kotlin-Object, I understand that since I am consuming a rest API I must use RetroFit. But that's where my question comes from, (My idea is to download the api (.json)) to keep it locally on the device, but I don't know how to pass it from the file "Locally".

Currently this is the code of how I get the api

//Url donde se aloja el api
private const val BASE_URL = "https://proyect.com/api/"

interface DataSetService {

    @GET("arch.json")
    fun getAllUser(): Deferred<List<DataSetItem>>
}

//Configuracion de moshi
//parse JSON into Kotlin objects
private val moshi = Moshi.Builder()
    .add(KotlinJsonAdapterFactory())
    .build()

object Network {
    //Obtenemos el api http y lo trasnformamos a moshi (kotlin Objects)
    private val retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(MoshiConverterFactory.create(moshi))
        .addCallAdapterFactory(CoroutineCallAdapterFactory())
        .build()
    val respuestaDataSet = retrofit.create(DataSetService::class.java)
}
question from:https://stackoverflow.com/questions/65941149/how-to-parse-a-json-local-file-with-moshi-in-kotlin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...