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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…