I am trying to read JSON file which is saved in my project locally and want to fetch and read using Kotlin Multiplatform Mobile, so I can share with Android and iOS
Following approch I'm doing:
In commonMain :
package com.example.readJSON.shared
import kotlinx.serialization.Serializable
@Serializable
data class DataRequest(
val dataRegimenRequest: List<DataRegimenRequest>?
)
expect class FileResource(location: String){
val json: String?
}
In androidMain :
package com.example.readJSON.shared
actual class FileResource actual constructor(location: String) {
actual val json: String? = this::class.java.classLoader!!.getResource(location)?.readText()
}
In iosMain :
package com.example.readJSON.shared
actual class FileResource actual constructor(location: String) {
actual val json: String? = null //TODO: write a code to read from local file
}
Can someone will help me, how can I fetch my local JSON file for iOS?
For Android, I am able to read local JSON file.